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

Method WriteMetaStringBytes

go/fory/meta_string_resolver.go:90–120  ·  view source on GitHub ↗
(buf *ByteBuffer, m *MetaStringBytes, err *Error)

Source from the content-addressed store, hash-verified

88}
89
90func (r *MetaStringResolver) WriteMetaStringBytes(buf *ByteBuffer, m *MetaStringBytes, err *Error) {
91 if m.DynamicWriteStringID == DefaultDynamicWriteMetaStrID {
92 // First occurrence: write full string data
93 m.DynamicWriteStringID = r.dynamicWriteStringID
94 r.dynamicWriteStringID++
95 r.dynamicWrittenEnumString = append(r.dynamicWrittenEnumString, m)
96
97 // WriteData header with length and encoding info
98 header := uint32(m.Length) << 1
99 buf.WriteVarUint32Small7(header)
100
101 // Small strings store encoding in header
102 if m.Length <= SmallStringThreshold {
103 if m.Length != 0 {
104 buf.WriteByte(byte(m.Encoding))
105 }
106 } else {
107 // Large strings include full hash
108 binErr := binary.Write(buf, binary.LittleEndian, m.Hashcode)
109 if binErr != nil {
110 err.SetError(binErr)
111 return
112 }
113 }
114 buf.Write(m.Data)
115 } else {
116 // Subsequent occurrence: write reference ID only
117 header := uint32((m.DynamicWriteStringID+1)<<1) | 1
118 buf.WriteVarUint32Small7(header)
119 }
120}
121
122// ReadMetaStringBytes reads a string from buffer, handling dynamic references
123func (r *MetaStringResolver) ReadMetaStringBytes(buf *ByteBuffer, ctxErr *Error) (*MetaStringBytes, error) {

Callers 2

TestMetaStringResolverFunction · 0.95
WriteTypeInfoMethod · 0.80

Calls 5

WriteVarUint32Small7Method · 0.80
WriteMethod · 0.65
uint32Function · 0.50
WriteByteMethod · 0.45
SetErrorMethod · 0.45

Tested by 1

TestMetaStringResolverFunction · 0.76