package libp2pwebrtc// The code in this file is adapted from the Go standard library's hex package.// As found in https://cs.opensource.google/go/go/+/refs/tags/go1.20.2:src/encoding/hex/hex.go//// The reason we adapted the original code is to allow us to deal with interspersed requirements// while at the same time hex encoding/decoding, without having to do so in two passes.import ()// encodeInterspersedHex encodes a byte slice into a string of hex characters,// separating each encoded byte with a colon (':').//// Example: { 0x01, 0x02, 0x03 } -> "01:02:03"func encodeInterspersedHex( []byte) string {iflen() == 0 {return"" } := hex.EncodeToString() := len()// Determine number of colons := / 2if %2 == 0 { -- } := make([]byte, +)for , := 0, 0; < ; , = +2, +3 {copy([:+2], [:+2])if +3 < len() { [+2] = ':' } }returnstring()}var errUnexpectedIntersperseHexChar = errors.New("unexpected character in interspersed hex string")// decodeInterspersedHexFromASCIIString decodes an ASCII string of hex characters into a byte slice,// where the hex characters are expected to be separated by a colon (':').//// NOTE that this function returns an error in case the input string contains non-ASCII characters.//// Example: "01:02:03" -> { 0x01, 0x02, 0x03 }func decodeInterspersedHexFromASCIIString( string) ([]byte, error) { := len() := make([]byte, /3*2+%3) := 0for := 0; < ; ++ {if %3 == 2 {if [] != ':' {returnnil, errUnexpectedIntersperseHexChar } } else {if [] == ':' {returnnil, errUnexpectedIntersperseHexChar } [] = [] ++ } } := make([]byte, hex.DecodedLen(len()))if , := hex.Decode(, ); != nil {returnnil, }return , nil}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.