1 /* 2 * Copyright (c) Facebook, Inc. and its affiliates. 3 * 4 * This source code is licensed under the MIT license found in the 5 * LICENSE file in the root directory of this source tree. 6 * 7 */ 8 9 #pragma once 10 11 #include <quic/server/handshake/AppToken.h> 12 13 #include <fizz/record/Types.h> 14 15 #include <folly/Optional.h> 16 17 namespace quic { 18 19 std::unique_ptr<folly::IOBuf> encodeAppToken(const AppToken& appToken); 20 21 folly::Optional<AppToken> decodeAppToken(const folly::IOBuf& buf); 22 23 } // namespace quic 24 25 namespace fizz { 26 namespace detail { 27 28 template <> 29 struct Reader<folly::IPAddress> { 30 template <class T> 31 size_t read(folly::IPAddress& ipAddress, folly::io::Cursor& cursor) { 32 std::unique_ptr<folly::IOBuf> sourceAddressBuf; 33 size_t len = readBuf<uint8_t>(sourceAddressBuf, cursor); 34 ipAddress = folly::IPAddress::fromBinary(sourceAddressBuf->coalesce()); 35 return len; 36 } 37 }; 38 39 template <> 40 struct Writer<folly::IPAddress> { 41 template <class T> 42 void write(const folly::IPAddress& ipAddress, folly::io::Appender& out) { 43 DCHECK(!ipAddress.empty()); 44 auto buf = 45 folly::IOBuf::wrapBuffer(ipAddress.bytes(), ipAddress.byteCount()); 46 writeBuf<uint8_t>(buf, out); 47 } 48 }; 49 50 template <> 51 struct Sizer<folly::IPAddress> { 52 template <class T> 53 size_t getSize(const folly::IPAddress& ipAddress) { 54 return sizeof(uint8_t) + ipAddress.byteCount(); 55 } 56 }; 57 58 } // namespace detail 59 } // namespace fizz 60