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

Function readMapStringInt32

go/fory/map_primitive.go:256–299  ·  view source on GitHub ↗

readMapStringInt32 reads map[string]int32 using chunk protocol

(ctx *ReadContext)

Source from the content-addressed store, hash-verified

254
255// readMapStringInt32 reads map[string]int32 using chunk protocol
256func readMapStringInt32(ctx *ReadContext) map[string]int32 {
257 err := ctx.Err()
258 buf := ctx.Buffer()
259 size, ok := readTypedMapSize(ctx)
260 result := make(map[string]int32)
261 if !ok {
262 return result
263 }
264 result = make(map[string]int32, size)
265
266 for size > 0 {
267 chunkHeader := buf.ReadUint8(err)
268 if chunkHeader&(TRACKING_KEY_REF|KEY_HAS_NULL|TRACKING_VALUE_REF|VALUE_HAS_NULL) != 0 {
269 ctx.SetError(DeserializationError("typed map reader does not support ref/null chunks"))
270 return result
271 }
272
273 chunkSize := int(buf.ReadUint8(err))
274 if ctx.HasError() {
275 return result
276 }
277 if chunkSize == 0 || chunkSize > size {
278 ctx.SetError(DeserializationErrorf("invalid map chunk size %d for remaining length %d", chunkSize, size))
279 return result
280 }
281 if (chunkHeader & KEY_DECL_TYPE) == 0 {
282 if !ctx.readExpectedTypeID(STRING) {
283 return result
284 }
285 }
286 if (chunkHeader & VALUE_DECL_TYPE) == 0 {
287 if !ctx.readExpectedTypeID(VARINT32) {
288 return result
289 }
290 }
291 for i := 0; i < chunkSize; i++ {
292 k := readString(buf, err)
293 v := buf.ReadVarint32(err)
294 result[k] = v
295 size--
296 }
297 }
298 return result
299}
300
301// writeMapStringInt writes map[string]int using chunk protocol
302// When hasGenerics=true, element types are known so we set DECL_TYPE flags and skip type info

Callers 1

ReadStringInt32MapMethod · 0.85

Calls 11

readTypedMapSizeFunction · 0.85
DeserializationErrorFunction · 0.85
DeserializationErrorfFunction · 0.85
readStringFunction · 0.85
ReadUint8Method · 0.80
readExpectedTypeIDMethod · 0.80
ErrMethod · 0.45
BufferMethod · 0.45
SetErrorMethod · 0.45
HasErrorMethod · 0.45
ReadVarint32Method · 0.45

Tested by

no test coverage detected