message-size-increase #3

Merged
sashakoshka merged 227 commits from message-size-increase into main 2025-09-07 19:27:38 -06:00
6 changed files with 144 additions and 45 deletions
Showing only changes of commit 8beb9de256 - Show all commits

View File

@ -7,12 +7,12 @@ PDL allows defining a protocol using HOPP and TAPE.
| Syntax | TN | CN | Description | Syntax | TN | CN | Description
| ---------- | ------- | -: | ----------- | ---------- | ------- | -: | -----------
| I5 | SI | | | I5 | SI | |
| I8 | LI | 0 | | I8 | LSI | 0 |
| I16 | LI | 1 | | I16 | LSI | 1 |
| I32 | LI | 3 | | I32 | LSI | 3 |
| I64 | LI | 7 | | I64 | LSI | 7 |
| I128[^2] | LI | 15 | | I128[^2] | LSI | 15 |
| I256[^2] | LI | 31 | | I256[^2] | LSI | 31 |
| U5 | SI | | | U5 | SI | |
| U8 | LI | 0 | | U8 | LI | 0 |
| U16 | LI | 1 | | U16 | LI | 1 |

View File

@ -307,8 +307,8 @@ func (this *Generator) generateMessage(method uint16, message Message) (n int, e
func (this *Generator) generateEncodeValue(typ Type, valueSource, tagSource string) (n int, err error) { func (this *Generator) generateEncodeValue(typ Type, valueSource, tagSource string) (n int, err error) {
switch typ := typ.(type) { switch typ := typ.(type) {
case TypeInt: case TypeInt:
// SI: (none) // SI: (none)
// LI: <value: IntN> // LI/LSI: <value: IntN>
if typ.Bits <= 5 { if typ.Bits <= 5 {
// SI stores the value in the tag, so we write nothing here // SI stores the value in the tag, so we write nothing here
break break
@ -478,8 +478,8 @@ func (this *Generator) generateEncodeValue(typ Type, valueSource, tagSource stri
func (this *Generator) generateDecodeValue(typ Type, typeName, valueSource, tagSource string) (n int, err error) { func (this *Generator) generateDecodeValue(typ Type, typeName, valueSource, tagSource string) (n int, err error) {
switch typ := typ.(type) { switch typ := typ.(type) {
case TypeInt: case TypeInt:
// SI: (none) // SI: (none)
// LI: <value: IntN> // LI/LSI: <value: IntN>
if typ.Bits <= 5 { if typ.Bits <= 5 {
// SI stores the value in the tag // SI stores the value in the tag
nn, err := this.iprintf("*%s = uint8(%s.CN())\n", valueSource, tagSource) nn, err := this.iprintf("*%s = uint8(%s.CN())\n", valueSource, tagSource)
@ -837,6 +837,9 @@ func (this *Generator) generateTag(typ Type, source string) (n int, err error) {
if typ.Bits <= 5 { if typ.Bits <= 5 {
nn, err := this.printf("tape.SI.WithCN(int(%s))", source) nn, err := this.printf("tape.SI.WithCN(int(%s))", source)
n += nn; if err != nil { return n, err } n += nn; if err != nil { return n, err }
} else if typ.Signed {
nn, err := this.printf("tape.LSI.WithCN(%d)", bitsToCN(typ.Bits))
n += nn; if err != nil { return n, err }
} else { } else {
nn, err := this.printf("tape.LI.WithCN(%d)", bitsToCN(typ.Bits)) nn, err := this.printf("tape.LI.WithCN(%d)", bitsToCN(typ.Bits))
n += nn; if err != nil { return n, err } n += nn; if err != nil { return n, err }
@ -881,6 +884,9 @@ func (this *Generator) generateTN(typ Type) (n int, err error) {
if typ.Bits <= 5 { if typ.Bits <= 5 {
nn, err := this.printf("tape.SI") nn, err := this.printf("tape.SI")
n += nn; if err != nil { return n, err } n += nn; if err != nil { return n, err }
} else if typ.Signed {
nn, err := this.printf("tape.LSI")
n += nn; if err != nil { return n, err }
} else { } else {
nn, err := this.printf("tape.LI") nn, err := this.printf("tape.LI")
n += nn; if err != nil { return n, err } n += nn; if err != nil { return n, err }

View File

@ -230,6 +230,26 @@ func TestGenerateRun(test *testing.T) {
Name: "NestedArray", Name: "NestedArray",
Type: TypeArray { Element: TypeArray { Element: TypeInt { Bits: 8 } } }, Type: TypeArray { Element: TypeArray { Element: TypeInt { Bits: 8 } } },
} }
protocol.Messages[0x0004] = Message {
Name: "Integers",
Type: TypeTableDefined {
Fields: map[uint16] Field {
0x0000: Field { Name: "U5", Type: TypeInt { Bits: 5 } },
0x0001: Field { Name: "U8", Type: TypeInt { Bits: 8 } },
0x0002: Field { Name: "U16", Type: TypeInt { Bits: 16 } },
0x0003: Field { Name: "U32", Type: TypeInt { Bits: 32 } },
0x0004: Field { Name: "U64", Type: TypeInt { Bits: 64 } },
0x0006: Field { Name: "I8", Type: TypeInt { Bits: 8, Signed: true } },
0x0007: Field { Name: "I16", Type: TypeInt { Bits: 16, Signed: true } },
0x0008: Field { Name: "I32", Type: TypeInt { Bits: 32, Signed: true } },
0x0009: Field { Name: "I64", Type: TypeInt { Bits: 64, Signed: true } },
0x000B: Field { Name: "NI8", Type: TypeInt { Bits: 8, Signed: true } },
0x000C: Field { Name: "NI16",Type: TypeInt { Bits: 16, Signed: true } },
0x000D: Field { Name: "NI32",Type: TypeInt { Bits: 32, Signed: true } },
0x000E: Field { Name: "NI64",Type: TypeInt { Bits: 64, Signed: true } },
},
},
}
protocol.Types["User"] = TypeTableDefined { protocol.Types["User"] = TypeTableDefined {
Fields: map[uint16] Field { Fields: map[uint16] Field {
0x0000: Field { Name: "Name", Type: TypeString { } }, 0x0000: Field { Name: "Name", Type: TypeString { } },