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

Method Decode

go/fory/meta/meta_string_decoder.go:38–66  ·  view source on GitHub ↗

Decode Accept an encodedBytes byte array, and the encoding method

(data []byte, encoding Encoding)

Source from the content-addressed store, hash-verified

36// Decode
37// Accept an encodedBytes byte array, and the encoding method
38func (d *Decoder) Decode(data []byte, encoding Encoding) (result string, err error) {
39 // we prepend one bit at the start to indicate whether strip last char
40 // so checking empty here will be convenient for decoding procedure
41 if data == nil {
42 return "", err
43 }
44 var chars []byte
45 switch encoding {
46 case LOWER_SPECIAL:
47 chars, err = d.decodeGeneric(data, encoding)
48 case LOWER_UPPER_DIGIT_SPECIAL:
49 chars, err = d.decodeGeneric(data, encoding)
50 case FIRST_TO_LOWER_SPECIAL:
51 chars, err = d.decodeGeneric(data, LOWER_SPECIAL)
52 if err == nil {
53 chars[0] = chars[0] - 'a' + 'A'
54 }
55 case ALL_TO_LOWER_SPECIAL:
56 chars, err = d.decodeRepAllToLowerSpecial(data, LOWER_SPECIAL)
57 case UTF_8:
58 chars = data
59 default:
60 err = fmt.Errorf("Unexpected encoding flag: %v\n", encoding)
61 }
62 if err != nil {
63 return "", err
64 }
65 return string(chars), err
66}
67
68// DecodeGeneric
69// algorithm is LowerSpecial or LowerUpperDigit

Callers 11

readMetaStringMethod · 0.95
StringMethod · 0.95
readUTF16LEFunction · 0.45
readPkgNameFunction · 0.45
readTypeNameFunction · 0.45
decodeTypeDefFunction · 0.45
readFieldDefFunction · 0.45

Calls 3

decodeGenericMethod · 0.95
stringFunction · 0.50

Tested by 1