MCPcopy Create free account
hub / github.com/apache/fory / decodeGeneric

Method decodeGeneric

go/fory/meta/meta_string_decoder.go:70–102  ·  view source on GitHub ↗

DecodeGeneric algorithm is LowerSpecial or LowerUpperDigit

(data []byte, algorithm Encoding)

Source from the content-addressed store, hash-verified

68// DecodeGeneric
69// algorithm is LowerSpecial or LowerUpperDigit
70func (d *Decoder) decodeGeneric(data []byte, algorithm Encoding) ([]byte, error) {
71 bitsPerChar := 5
72 if algorithm == LOWER_UPPER_DIGIT_SPECIAL {
73 bitsPerChar = 6
74 }
75 // Retrieve 5 bits every iteration from data, convert them to characters, and save them to chars
76 // "abc" encodedBytes as [00000] [000,01] [00010] [0, corresponding to three bytes, which are 0, 68, 0
77 // Take the highest digit first, then the lower, in order
78
79 // here access data[0] before entering the loop, so we had to deal with empty data in Decode method
80 // totChars * bitsPerChar <= totBits < (totChars + 1) * bitsPerChar
81 stripLastChar := (data[0] & 0x80) >> 7
82 totBits := len(data)*8 - 1 - int(stripLastChar)*bitsPerChar
83 totChars := totBits / bitsPerChar
84 chars := make([]byte, totChars)
85 bitPos, bitCount := 6, 1 // first highest bit indicates whether strip last char
86 for i := 0; i < totChars; i++ {
87 var val byte = 0
88 for i := 0; i < bitsPerChar; i++ {
89 if data[bitCount/8]&(1<<bitPos) > 0 {
90 val |= 1 << (bitsPerChar - i - 1)
91 }
92 bitPos = (bitPos - 1 + 8) % 8
93 bitCount++
94 }
95 ch, err := d.decodeChar(val, algorithm)
96 if err != nil {
97 return nil, err
98 }
99 chars[i] = ch
100 }
101 return chars, nil
102}
103
104func (d *Decoder) decodeRepAllToLowerSpecial(data []byte, algorithm Encoding) ([]byte, error) {
105 // Decode the data to the lowercase letters, then convert

Callers 2

DecodeMethod · 0.95

Calls 1

decodeCharMethod · 0.95

Tested by

no test coverage detected