diff options
Diffstat (limited to 'vendor/github.com/hamba/avro/v2/encoder.go')
| -rw-r--r-- | vendor/github.com/hamba/avro/v2/encoder.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/vendor/github.com/hamba/avro/v2/encoder.go b/vendor/github.com/hamba/avro/v2/encoder.go new file mode 100644 index 0000000..faa285e --- /dev/null +++ b/vendor/github.com/hamba/avro/v2/encoder.go @@ -0,0 +1,37 @@ +package avro + +import ( + "io" +) + +// Encoder writes Avro values to an output stream. +type Encoder struct { + s Schema + w *Writer +} + +// NewEncoder returns a new encoder that writes to w using schema s. +func NewEncoder(s string, w io.Writer) (*Encoder, error) { + sch, err := Parse(s) + if err != nil { + return nil, err + } + return NewEncoderForSchema(sch, w), nil +} + +// NewEncoderForSchema returns a new encoder that writes to w using schema. +func NewEncoderForSchema(schema Schema, w io.Writer) *Encoder { + return DefaultConfig.NewEncoder(schema, w) +} + +// Encode writes the Avro encoding of v to the stream. +func (e *Encoder) Encode(v any) error { + e.w.WriteVal(e.s, v) + _ = e.w.Flush() + return e.w.Error +} + +// Marshal returns the Avro encoding of v. +func Marshal(schema Schema, v any) ([]byte, error) { + return DefaultConfig.Marshal(schema, v) +} |
