MCPcopy Index your code
hub / github.com/google/go-cloud / Decoder

Interface Decoder

docstore/driver/codec.go:324–369  ·  view source on GitHub ↗

TODO(jba): consider a fast path: if we are decoding into a struct, assume the same struct was used to encode. Then we can build a map from field names to functions, where each function avoids all the tests of Decode and contains just the code for setting the field. TODO(jba): provide a way to overr

Source from the content-addressed store, hash-verified

322// A Decoder decodes data that was produced by Encode back into Go values.
323// Each Decoder instance is responsible for decoding one value.
324type Decoder interface {
325 // The AsXXX methods each report whether the value being decoded can be represented as
326 // a particular Go type. If so, the method should return the value as that type, and true;
327 // otherwise it should return the zero value and false.
328 AsString() (string, bool)
329 AsInt() (int64, bool)
330 AsUint() (uint64, bool)
331 AsFloat() (float64, bool)
332 AsBytes() ([]byte, bool)
333 AsBool() (bool, bool)
334 AsNull() bool
335
336 // ListLen should return the length of the value being decoded and true, if the
337 // value can be decoded into a slice or array. Otherwise, ListLen should return
338 // (0, false).
339 ListLen() (int, bool)
340
341 // If ListLen returned true, then DecodeList will be called. It should iterate
342 // over the value being decoded in sequence from index 0, invoking the callback
343 // for each element with the element's index and a Decoder for the element.
344 // If the callback returns false, DecodeList should return immediately.
345 DecodeList(func(int, Decoder) bool)
346
347 // MapLen should return the number of fields of the value being decoded and true,
348 // if the value can be decoded into a map or struct. Otherwise, it should return
349 // (0, false).
350 MapLen() (int, bool)
351
352 // DecodeMap iterates over the fields of the value being decoded, invoke the
353 // callback on each with field name, a Decoder for the field value, and a bool
354 // to indicate whether or not to use exact match for the field names. It will
355 // be called when MapLen returns true or decoding a struct. If the callback
356 // returns false, DecodeMap should return immediately.
357 DecodeMap(func(string, Decoder, bool) bool)
358
359 // AsInterface should decode the value into the Go value that best represents it.
360 AsInterface() (any, error)
361
362 // If the decoder wants to decode a value in a special way it should do so here
363 // and return true, the decoded value, and any error from the decoding.
364 // Otherwise, it should return false.
365 AsSpecial(reflect.Value) (bool, any, error)
366
367 // String should return a human-readable representation of the Decoder, for error messages.
368 String() string
369}
370
371// Decode decodes the value held in the Decoder d into v.
372// Decode creates slices, maps and pointer elements as needed.

Callers 35

TestOpenTelemetryFunction · 0.65
decodeFunction · 0.65
TestOpenTelemetryFunction · 0.65
decodeFunction · 0.65
decodeFunction · 0.65
AsComplexMethod · 0.65
decodeFunction · 0.65
decodeFunction · 0.65
decodeListFunction · 0.65
decodeFunction · 0.65
decodeFunction · 0.65
decodeListFunction · 0.65

Implementers 6

decoderdocstore/memdocstore/codec.go
decoderdocstore/awsdynamodb/v2/codec.go
decoderdocstore/gcpfirestore/codec.go
testDecoderdocstore/driver/codec_test.go
failDecoderdocstore/driver/codec_test.go
decoderdocstore/mongodocstore/codec.go

Calls

no outgoing calls

Tested by

no test coverage detected