Skip to content

Commit

Permalink
update the doc and add some tests for the generalization of counting
Browse files Browse the repository at this point in the history
  • Loading branch information
rom1504 committed May 8, 2016
1 parent de9d4e1 commit 03b7ea4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
12 changes: 12 additions & 0 deletions doc/datatypes.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ It takes for arguments:
* countType : the type of the length prefix
* count : optional (either count or countType), a reference to the field counting the elements, or a fixed size (an integer)

See [Counting](#Counting)

Example:

Expand Down Expand Up @@ -185,6 +186,8 @@ Example of value : `true`
A length prefixed string. It takes one argument : the type of the length prefix.
It is usually used to define a "string" type that can be used without argument.

The count can also be defined in different ways, see [Counting](#Counting).

Example:

A string length prefixed by a varint.
Expand All @@ -207,6 +210,8 @@ It takes for arguments:
* countType : the type of the length prefix
* count : optional (either count or countType), a reference to the field counting the elements, or a fixed size (an integer)

See [Counting](#Counting)

Example:

An buffer prefixed by a varint length.
Expand Down Expand Up @@ -278,3 +283,10 @@ Maps a byte to a string, 1 to "byte", 2 to "short", 3 to "int", 4 to "long".
```

Example of value: `3`

# Common datatypes arguments

## Counting

* countType : the type of the length prefix
* count : optional (either count or countType), a reference to the field counting the elements, or a fixed size (an integer)
30 changes: 30 additions & 0 deletions test/utils.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@
{
"type":"buffer",
"subtypes":[
{
"description":"a fixed size buffer",
"type":["buffer",
{
"count":3
}
],
"values":[
{
"value":["0x05","0x10","0xAE"],
"buffer":["0x05","0x10","0xAE"]
}
]
},
{
"description":"an u8 prefixed buffer",
"type":["buffer",
Expand All @@ -85,6 +99,22 @@
{
"type":"pstring",
"subtypes":[
{

"description":"fixed size string",
"type":[
"pstring",{
"count":6
}
],
"values":[
{
"description":"simple hello",
"buffer":[ "0x48", "0x65", "0x6C", "0x6C", "0x6F", "0x21"],
"value":"Hello!"
}
]
},
{
"description":"i16 prefixed string",
"type":[
Expand Down

0 comments on commit 03b7ea4

Please sign in to comment.