| 88 | } |
| 89 | |
| 90 | func (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 |
| 123 | func (r *MetaStringResolver) ReadMetaStringBytes(buf *ByteBuffer, ctxErr *Error) (*MetaStringBytes, error) { |