summaryrefslogtreecommitdiff
path: root/vendor/github.com/hamba/avro/v2/decoder.go
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-07-22 17:35:49 -0600
committermo khan <mo@mokhan.ca>2025-07-22 17:35:49 -0600
commit20ef0d92694465ac86b550df139e8366a0a2b4fa (patch)
tree3f14589e1ce6eb9306a3af31c3a1f9e1af5ed637 /vendor/github.com/hamba/avro/v2/decoder.go
parent44e0d272c040cdc53a98b9f1dc58ae7da67752e6 (diff)
feat: connect to spicedb
Diffstat (limited to 'vendor/github.com/hamba/avro/v2/decoder.go')
-rw-r--r--vendor/github.com/hamba/avro/v2/decoder.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/vendor/github.com/hamba/avro/v2/decoder.go b/vendor/github.com/hamba/avro/v2/decoder.go
new file mode 100644
index 0000000..0e0ab9d
--- /dev/null
+++ b/vendor/github.com/hamba/avro/v2/decoder.go
@@ -0,0 +1,49 @@
+package avro
+
+import (
+ "io"
+)
+
+// Decoder reads and decodes Avro values from an input stream.
+type Decoder struct {
+ s Schema
+ r *Reader
+}
+
+// NewDecoder returns a new decoder that reads from reader r using schema s.
+func NewDecoder(s string, r io.Reader) (*Decoder, error) {
+ sch, err := Parse(s)
+ if err != nil {
+ return nil, err
+ }
+
+ return NewDecoderForSchema(sch, r), nil
+}
+
+// NewDecoderForSchema returns a new decoder that reads from r using schema.
+func NewDecoderForSchema(schema Schema, reader io.Reader) *Decoder {
+ return DefaultConfig.NewDecoder(schema, reader)
+}
+
+// Decode reads the next Avro encoded value from its input and stores it in the value pointed to by v.
+func (d *Decoder) Decode(v any) error {
+ if d.r.head == d.r.tail && d.r.reader != nil {
+ if !d.r.loadMore() {
+ return io.EOF
+ }
+ }
+
+ d.r.ReadVal(d.s, v)
+
+ //nolint:errorlint // Only direct EOF errors should be discarded.
+ if d.r.Error == io.EOF {
+ return nil
+ }
+ return d.r.Error
+}
+
+// Unmarshal parses the Avro encoded data and stores the result in the value pointed to by v.
+// If v is nil or not a pointer, Unmarshal returns an error.
+func Unmarshal(schema Schema, data []byte, v any) error {
+ return DefaultConfig.Unmarshal(schema, data, v)
+}