MCPcopy Create free account
hub / github.com/blues/note / BulkEncodeTemplate

Function BulkEncodeTemplate

lib/bulk.go:1082–1102  ·  view source on GitHub ↗

BulkEncodeTemplate sets up a context for encoding by taking the template and preparing a binary output buffer

(templateBodyJSON []byte)

Source from the content-addressed store, hash-verified

1080
1081// BulkEncodeTemplate sets up a context for encoding by taking the template and preparing a binary output buffer
1082func BulkEncodeTemplate(templateBodyJSON []byte) (context BulkTemplateContext, err error) {
1083 body := BulkBody{}
1084 err = note.JSONUnmarshal(templateBodyJSON, &body)
1085 if err != nil {
1086 err = fmt.Errorf("couldn't unmarshal bulk template: %w", err)
1087 return
1088 }
1089 if body.NoteFormat != BulkNoteFormatFlex && body.NoteFormat != BulkNoteFormatFlexNano {
1090 err = fmt.Errorf("bulk template: unrecognized or unsupported format: %d", body.NoteFormat)
1091 return
1092 }
1093
1094 // Set up the context
1095 context.NoteFormat = body.NoteFormat
1096 context.Template = body.NoteTemplate
1097 context.Bin = []byte{}
1098 context.MaxArrayLength = 65535 // uint16_t max
1099
1100 // Done
1101 return
1102}
1103
1104// BulkEncodeNextEntry encodes a JSON object using the template in the supplied contxt
1105//

Callers 6

TestBulkEncodeFunction · 0.85
TestVariableLengthArraysFunction · 0.85
TestBulkFlagNoVariableFunction · 0.85
TestBulkEncodeDecodeFunction · 0.85
TestOLCEncodingRoundTripFunction · 0.85
TestBulkTimeFieldType23Function · 0.85

Calls

no outgoing calls

Tested by 6

TestBulkEncodeFunction · 0.68
TestVariableLengthArraysFunction · 0.68
TestBulkFlagNoVariableFunction · 0.68
TestBulkEncodeDecodeFunction · 0.68
TestOLCEncodingRoundTripFunction · 0.68
TestBulkTimeFieldType23Function · 0.68