v0.0.157
This commit is contained in:
54
wmo/decoding.go
Normal file
54
wmo/decoding.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package wmo
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
func (c *Coll[TData]) decodeSingle(ctx context.Context, dec Decodable) (TData, error) {
|
||||
if c.customDecoder != nil {
|
||||
|
||||
return (*c.customDecoder)(ctx, dec)
|
||||
|
||||
} else {
|
||||
|
||||
var res TData
|
||||
|
||||
err := dec.Decode(&res)
|
||||
if err != nil {
|
||||
return *new(TData), err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Coll[TData]) decodeAll(ctx context.Context, cursor Cursorable) ([]TData, error) {
|
||||
if c.customDecoder != nil {
|
||||
|
||||
res := make([]TData, 0, cursor.RemainingBatchLength())
|
||||
|
||||
for cursor.Next(ctx) {
|
||||
entry, err := (*c.customDecoder)(ctx, cursor)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res = append(res, entry)
|
||||
}
|
||||
|
||||
return res, nil
|
||||
|
||||
} else {
|
||||
|
||||
res := make([]TData, 0, cursor.RemainingBatchLength())
|
||||
|
||||
err := cursor.All(ctx, &res)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user