Swiftpack.co - Package - std-swift/Encoding

Encoding

Hex strings, endinanness, and bit packing

Importing

import Encoding
dependencies: [
	.package(url: "https://github.com/std-swift/Encoding.git",
	         from: "1.1.0")
],
targets: [
	.target(
		name: "",
		dependencies: [
			"Encoding"
		]),
]

Using

FixedWidthInteger

  • littleEndianBytes: [UInt8]
  • bigEndianBytes: [UInt8]

Array where Element == UInt8

  • hexString: String

Array where Element: BinaryInteger

func asArray<T: BinaryInteger>(endinanness: Endianness, sourceBits: Int, resultBits: Int) -> [T]
func asBigEndian<T: BinaryInteger>(sourceBits: Int = Element().bitWidth, resultBits: Int = T().bitWidth) -> [T]
func asLittleEndian<T: BinaryInteger>(sourceBits: Int = Element().bitWidth, resultBits: Int = T().bitWidth) -> [T]

StreamDecoder

/// Decodes a stream of `Element` returning `Partial` values when possible
public protocol StreamDecoder {
	associatedtype Element
	associatedtype Partial
	associatedtype Decoded
	
	/// Decode a sequence of `Element` and buffer the decoded value
	mutating func decode<T: Sequence>(_ elements: T) where T.Element == Element
	
	/// Decode a sequence of `Element` and return the buffered value
	mutating func decodePartial<T: Sequence>(_ elements: T) -> Partial where T.Element == Element
	
	/// Finalizes the decoder state and returns the buffered value
	///
	/// Finalizing consumes the StreamDecoder
	mutating func finalize() -> Decoded
}

StreamEncoder

/// Encodes a stream of `Element` returning `Partial` values when possible
public protocol StreamEncoder {
	associatedtype Element
	associatedtype Partial
	associatedtype Encoded
	
	/// Encode a sequence of `Element` and buffer the encoded value
	mutating func encode<T: Sequence>(_ elements: T) where T.Element == Element
	
	/// Encode a sequence of `Element` and return the buffered value
	mutating func encodePartial<T: Sequence>(_ elements: T) -> Partial where T.Element == Element
	
	/// Finalizes the encoder state and returns the buffered value
	///
	/// Finalizing consumes the StreamEncoder
	mutating func finalize() -> Encoded
}

Github

link
Stars: 0
Help us keep the lights on

Dependencies

Used By

Total: 2