mirror of
https://github.com/apple/swift-nio-extras.git
synced 2025-06-02 19:16:25 +08:00
* Adds a LengthFieldPrepender class to prepend the length onto a message. This class is a type of byte to message encoder. Motivation: To encode a prepended length field on data so that messages of arbitrary size can be sent. Can work as a pair with the ‘LengthFieldBasedFrameDecoder’. Modifications: Added ‘LengthFieldPrepender’ Added unit tests for ‘LengthFieldPrepender’ in ‘LengthFieldPrependerTest’ Updated the linux text files by running the script. Result: The length can now be easily prepended to any message.
43 lines
1.7 KiB
Swift
43 lines
1.7 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftNIO open source project
|
|
//
|
|
// Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// LengthFieldPrependerTest+XCTest.swift
|
|
//
|
|
import XCTest
|
|
|
|
///
|
|
/// NOTE: This file was generated by generate_linux_tests.rb
|
|
///
|
|
/// Do NOT edit this file directly as it will be regenerated automatically when needed.
|
|
///
|
|
|
|
extension LengthFieldPrependerTest {
|
|
|
|
static var allTests : [(String, (LengthFieldPrependerTest) -> () throws -> Void)] {
|
|
return [
|
|
("testEncodeWithUInt8HeaderWithData", testEncodeWithUInt8HeaderWithData),
|
|
("testEncodeWithUInt16HeaderWithString", testEncodeWithUInt16HeaderWithString),
|
|
("testEncodeWithUInt32HeaderWithString", testEncodeWithUInt32HeaderWithString),
|
|
("testEncodeWithUInt64HeaderWithString", testEncodeWithUInt64HeaderWithString),
|
|
("testEncodeWithInt64HeaderWithString", testEncodeWithInt64HeaderWithString),
|
|
("testEncodeWithUInt64HeaderStringBigEndian", testEncodeWithUInt64HeaderStringBigEndian),
|
|
("testEncodeWithInt64HeaderStringDefaultingToBigEndian", testEncodeWithInt64HeaderStringDefaultingToBigEndian),
|
|
("testEmptyBuffer", testEmptyBuffer),
|
|
("testLargeBuffer", testLargeBuffer),
|
|
("testTooLargeForLengthField", testTooLargeForLengthField),
|
|
]
|
|
}
|
|
}
|
|
|