BulkEncodeTemplate sets up a context for encoding by taking the template and preparing a binary output buffer
(templateBodyJSON []byte)
| 1080 | |
| 1081 | // BulkEncodeTemplate sets up a context for encoding by taking the template and preparing a binary output buffer |
| 1082 | func 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 | // |
no outgoing calls