Merge codec and tape packages
This commit is contained in:
@@ -6,12 +6,11 @@ import "maps"
|
||||
import "math"
|
||||
import "slices"
|
||||
import "strings"
|
||||
import "git.tebibyte.media/sashakoshka/hopp/codec"
|
||||
import "git.tebibyte.media/sashakoshka/hopp/tape"
|
||||
|
||||
const imports =
|
||||
`
|
||||
import "git.teibibyte.media/sashakoshka/hopp/tape"
|
||||
import "git.teibibyte.media/sashakoshka/hopp/codec"
|
||||
`
|
||||
|
||||
const preamble = `
|
||||
@@ -31,8 +30,8 @@ type Table map[uint16] any
|
||||
|
||||
// Message is any message that can be sent along this protocol.
|
||||
type Message interface {
|
||||
codec.Encodable
|
||||
codec.Decodable
|
||||
tape.Encodable
|
||||
tape.Decodable
|
||||
|
||||
// Method returns the method code of the message.
|
||||
Method() uint16
|
||||
@@ -122,7 +121,7 @@ func (this *Generator) generateTypedef(name string, typ Type) (n int, err error)
|
||||
"specified by the tag, if possible.\n")
|
||||
n += nn; if err != nil { return n, err }
|
||||
nn, err = this.iprintf(
|
||||
"func (this *%s) EncodeValue(encoder *codec.Encoder, tag tape.Tag) (n int, err error) {\n",
|
||||
"func (this *%s) EncodeValue(encoder *tape.Encoder, tag tape.Tag) (n int, err error) {\n",
|
||||
name)
|
||||
n += nn; if err != nil { return n, err }
|
||||
this.push()
|
||||
@@ -136,7 +135,21 @@ func (this *Generator) generateTypedef(name string, typ Type) (n int, err error)
|
||||
nn, err = this.iprintf("}\n")
|
||||
n += nn; if err != nil { return n, err }
|
||||
|
||||
// TODO DecodeValue method
|
||||
// DecodeValue method
|
||||
nn, err = this.iprintf(
|
||||
"\n // DecodeValue decodes the value of this type without " +
|
||||
"the tag. The value is\n// decoded according to the " +
|
||||
"parameters specified by the tag, if possible.\n")
|
||||
n += nn; if err != nil { return n, err }
|
||||
nn, err = this.iprintf(
|
||||
"func (this *%s) DecodeValue(decoder *tape.Decoder, tag tape.Tag) (n int, err error) {\n",
|
||||
name)
|
||||
n += nn; if err != nil { return n, err }
|
||||
this.push()
|
||||
// TODO
|
||||
this.pop()
|
||||
nn, err = this.iprintf("}\n")
|
||||
n += nn; if err != nil { return n, err }
|
||||
|
||||
return n, nil
|
||||
}
|
||||
@@ -156,7 +169,7 @@ func (this *Generator) generateMessage(method uint16, message Message) (n int, e
|
||||
nn, err = this.iprintf("\n// Encode encodes this message's tag and value.\n")
|
||||
n += nn; if err != nil { return n, err }
|
||||
nn, err = this.iprintf(
|
||||
"func(this %s) Encode(encoder *codec.Encoder) (n int, err error) {\n",
|
||||
"func(this %s) Encode(encoder *tape.Encoder) (n int, err error) {\n",
|
||||
this.resolveMessageName(message.Name))
|
||||
n += nn; if err != nil { return n, err }
|
||||
this.push()
|
||||
@@ -378,7 +391,7 @@ func (this *Generator) generateTag(typ Type, source string) (n int, err error) {
|
||||
nn, err := this.printf("tape.TagKTV.WithCN(tape.IntBytes(uint64(len(%s))))", source)
|
||||
n += nn; if err != nil { return n, err }
|
||||
case TypeTableDefined:
|
||||
nn, err := this.printf("tape.TagKTV.WithCN(%d)", codec.IntBytes(uint64(len(typ.Fields))))
|
||||
nn, err := this.printf("tape.TagKTV.WithCN(%d)", tape.IntBytes(uint64(len(typ.Fields))))
|
||||
n += nn; if err != nil { return n, err }
|
||||
case TypeNamed:
|
||||
resolved, err := this.resolveTypeName(typ.Name)
|
||||
|
||||
Reference in New Issue
Block a user