tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

NrIceStunAddrMessageUtils.h (1502B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #ifndef mozilla_net_NrIceStunAddrMessageUtils_h
      6 #define mozilla_net_NrIceStunAddrMessageUtils_h
      7 
      8 // forward declare NrIceStunAddr for --disable-webrtc builds where
      9 // the header will not be available.
     10 namespace mozilla {
     11 class NrIceStunAddr;
     12 }  // namespace mozilla
     13 
     14 #include "ipc/IPCMessageUtils.h"
     15 #ifdef MOZ_WEBRTC
     16 #  include "transport/nricestunaddr.h"
     17 #endif
     18 
     19 namespace IPC {
     20 
     21 template <>
     22 struct ParamTraits<mozilla::NrIceStunAddr> {
     23  static void Write(MessageWriter* aWriter,
     24                    const mozilla::NrIceStunAddr& aParam) {
     25 #ifdef MOZ_WEBRTC
     26    const size_t bufSize = aParam.SerializationBufferSize();
     27    char* buffer = new char[bufSize];
     28    aParam.Serialize(buffer, bufSize);
     29    aWriter->WriteBytes((void*)buffer, bufSize);
     30    delete[] buffer;
     31 #endif
     32  }
     33 
     34  static bool Read(MessageReader* aReader, mozilla::NrIceStunAddr* aResult) {
     35 #ifdef MOZ_WEBRTC
     36    const size_t bufSize = aResult->SerializationBufferSize();
     37    char* buffer = new char[bufSize];
     38    bool result = aReader->ReadBytesInto((void*)buffer, bufSize);
     39 
     40    if (result) {
     41      result = result && (NS_OK == aResult->Deserialize(buffer, bufSize));
     42    }
     43    delete[] buffer;
     44 
     45    return result;
     46 #else
     47    return false;
     48 #endif
     49  }
     50 };
     51 
     52 }  // namespace IPC
     53 
     54 #endif  // mozilla_net_NrIceStunAddrMessageUtils_h