Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NewLazyValue constructor #11

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions nexus/serializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ type LazyValue struct {
Reader *Reader
}

// Create a new [LazyValue] from a given serializer and reader.
func NewLazyValue(serializer Serializer, reader *Reader) *LazyValue {
return &LazyValue{
serializer: serializer,
Reader: reader,
}
}

// Consume consumes the lazy value, decodes it from the underlying [Reader], and stores the result in the value pointed
// to by v.
//
Expand Down Expand Up @@ -123,7 +131,7 @@ func (jsonSerializer) Serialize(v any) (*Content, error) {
}
return &Content{
Header: Header{
"type": "application/json",
"type": "application/json",
},
Data: data,
}, nil
Expand Down Expand Up @@ -201,7 +209,7 @@ func (byteSliceSerializer) Serialize(v any) (*Content, error) {
if b, ok := v.([]byte); ok {
return &Content{
Header: Header{
"type": "application/octet-stream",
"type": "application/octet-stream",
},
Data: b,
}, nil
Expand Down
Loading