aboutsummaryrefslogtreecommitdiff
path: root/reader_test.go (unfollow)
Commit message (Collapse)AuthorFilesLines
2024-10-21More fork URL changesRunxi Yu9-13/+15
2024-10-21Fork initRunxi Yu2-9/+11
2021-04-06Fix typoMartin Vahlensieck1-1/+1
2021-04-01schema: fix unparse unit testsSimon Ser1-2/+2
The previous commit has broken them. Fixes: a9d281db6bd4 ("schema: fix int/uint in SchemaForType")
2021-04-01schema: fix int/uint in SchemaForTypeSimon Ser1-2/+2
These were not handled like the rest of the package does. See [1]. [1]: https://lists.sr.ht/~sircmpwn/public-inbox/%3CnXLRyQhz5KLITkQadNKRWNfYZJ7AuWRi9MRJZjmaNEMQ-DSv2edqNMC5BngmwloIebE8cU_l35xjEpIjJ8-77S44tzwbmjWqXcMm_-FcLQU%3D%40emersion.fr%3E
2021-03-31Add dedicated Int and Uint typesSimon Ser6-4/+63
Go's int and uitn are no guaranteed to be able to hold 64 bits worth of data.
2021-03-31Panic when decode{Uint,Int,Float} are passed a wrong valueSimon Ser1-0/+8
2021-03-31Remove misleading docsSimon Ser2-6/+0
Go `int` and `uint` are encoded as variable-length integers.
2021-03-31Expose UnmarshalBareReaderSimon Ser1-3/+3
This allows the caller to read multiple values without having to re-create a *Reader in-between.
2021-03-31Optimize io.ByteBuffer in NewReaderSimon Ser1-16/+16
If the supplied io.Reader is already an io.ByteBuffer, no need to wrap it with a bufferedReader. Change the bufferedReader scratch byte buffer to be an array instead of a slice. This allows us to save an extra allocation. While at it, rename bufferedReader to simpleByteReader. This reader isn't really buffered, it just exposes an extra ReadByte function.
2021-03-30readme: use godocs.io for documentation badgeSimon Ser1-1/+1
2021-02-27Copy marshaled message into new sliceTimofey1-1/+5
Since we use a pool of temporary buffers returning a slice poining to buffer storage is dangerous since its contents may get overwritten by another thread. This can potentially cause major security issues.
2020-12-10example: update schema to match current state of rfcJohn Mulligan2-2/+2
The rfc no longer specifies a type after the enum name. Remove this type specification and regenerate the example go file. Signed-off-by: John Mulligan <phlogistonjohn@asynchrono.us>
2020-12-10gen: add UINT and INT types to template mappingJohn Mulligan1-0/+4
The UINT and INT types were not present in the generator and caused enums generation to fail. Signed-off-by: John Mulligan <phlogistonjohn@asynchrono.us>
2020-12-10ast: add String method to TypeKind to ease future debuggingJohn Mulligan1-0/+59
Making the (largish) enum of TypeKind meet the Stringer interface makes it easier to map the value of the enum to "what is is". I found this tweak eased my debugging of a failure to generate from a bare schema file. Signed-off-by: John Mulligan <phlogistonjohn@asynchrono.us>
2020-12-06gen: only add errors import if type needs errors packageJohn Mulligan1-3/+10
The errors package will only be imported if its needed later in the code. Currently this is only if an enum is generated. Signed-off-by: John Mulligan <phlogistonjohn@asynchrono.us>
2020-11-20reader, writer: error on NaNDrew DeVault3-2/+25
2020-11-17Omit struct fields with a field tag of "-".Adnan Maolood4-0/+45
2020-11-06allow unions to roundtrip without errorsDaniel Martí2-1/+28
If a union contains a type T, when decoding into a struct field of said union type, we would end up with a value of type *T. This is fine for Unmarshal itself. However, Marshal errors when it encounters *T instead of T for that union, because the ut.tags map does not contain *T. Teach it to reach past the pointer if it encounters *T instead of T, so that it can encode the type T. Add a simple test round-tripping what's explained above, which fails without the fix: marshal_test.go:274: Error Trace: marshal_test.go:274 Error: Expected nil, but got: &errors.errorString{s:"Invalid union value: <*bare.Age Value>"} Test: TestRoundtrip
2020-11-02Reuse marshal buffersTimofey1-1/+15
2020-11-02Configurable map & array size limitsTimofey3-3/+35
2020-11-02Reject invalid valuesTimofey5-12/+50
* Check if string is valid utf8 * Reject non-binary bool and optional values * Raise on duplicate map keys * Add tests See draft spec: https://tools.ietf.org/html/draft-devault-bare-00
2020-11-02Fix test assertionsTimofey1-18/+18
2020-11-02Prevent extra allocations in reader/writerTimofey2-39/+57
* Use interface instead of concrete reader type to prevent runtime.convT2I allocations * Use scratch buffers for integer-related operations
2020-11-02Cache encoding/decoding routinesTimofey5-231/+464
* Add tests for custom types
2020-11-02Add example benchmarksTimofey2-0/+52
2020-10-09Refactor cmd/genTimofey3-302/+296
* Use text/template instead of manually writing to output file * Format generated code with gofmt
2020-08-12Read minimum number of bytes necessary from ReaderNoah Pederson8-42/+163
When using bare.UnmarshalReader the interal bufio.Reader may overzealously read more bytes than is necessary to decode the message. By dropping the buffered reader from bufio in favor of a single byte buffered reader, we can minimize the number of bytes read from the input io.Reader. By doing this, we can call bare.UnmarshalReader multiple times on the same stream to decode multiple messages. See example/stream/stream.go for a reference on how this may be done. Includes a basic test. Also moves the existing example into a subfolder and creates a new folder for the stream test so both can be run using `go run`.
2020-06-23example/*.bin: trim off line feedDrew DeVault3-1/+1
I wrote these files with xxd in vim and vim automatically inserts a newline at the end of the file, the bastard
2020-06-23Implement void typesDrew DeVault10-6/+37
2020-06-22Add maximum message size limitDrew DeVault3-7/+63
2020-06-22Implement explicit union tag specificationDrew DeVault2-10/+50
2020-06-22Generalize union implementationDrew DeVault10-48/+112
In preparation for user-defined tag values
2020-06-22README.md: update URL to specDrew DeVault1-1/+1
2020-06-22Update customer.bin, employee.bin to latest formatDrew DeVault2-0/+0
2020-06-22parser: implement default storage for enumsDrew DeVault2-2/+14
2020-06-22Use uint for internal length encodingsDrew DeVault8-35/+35
2020-06-22Marshal, Unmarshal: implement uint & intDrew DeVault5-47/+34
2020-06-22parser: parse int & uintDrew DeVault3-1/+11
2020-06-22lex: scan uint & intDrew DeVault2-0/+12
2020-06-22reader_test.go: remove excessive messagingDrew DeVault1-50/+46
2020-06-22reader, writer: implement varintsDrew DeVault4-2/+79
2020-06-22parse: correctly implement enum value assignmentDrew DeVault1-1/+2
2020-06-22Drop e8/e16/e32/e64 in favor of u8/u16/u32/u64Drew DeVault9-89/+13
2020-06-21Update README.mdDrew DeVault1-0/+9
2020-06-21marshal, unmarshal: add CanAddress guardDrew DeVault2-4/+8
2020-06-21example: correct typoDrew DeVault1-1/+1
2020-06-21gen: implement unionsDrew DeVault7-23/+137
2020-06-21Add Marshalable and Unmarshalable interfacesDrew DeVault2-3/+25
2020-06-21Further simplify union implementationDrew DeVault5-16/+28