Merge codec and tape packages
This commit is contained in:
parent
ce503c4689
commit
285e83d995
@ -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)
|
||||
|
@ -1,4 +1,4 @@
|
||||
package codec
|
||||
package tape
|
||||
|
||||
import "io"
|
||||
|
@ -2,7 +2,6 @@ package tape
|
||||
|
||||
import "fmt"
|
||||
import "reflect"
|
||||
import "git.tebibyte.media/sashakoshka/hopp/codec"
|
||||
|
||||
// EncodeAny encodes an "any" value. Returns an error if the underlying type is
|
||||
// unsupported. Supported types are:
|
||||
@ -14,7 +13,7 @@ import "git.tebibyte.media/sashakoshka/hopp/codec"
|
||||
// - string
|
||||
// - []<supported type>
|
||||
// - map[uint16]<supported type>
|
||||
func EncodeAny(encoder *codec.Encoder, value any) (Tag, error) {
|
||||
func EncodeAny(encoder *Encoder, value any) (Tag, error) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package codec
|
||||
package tape
|
||||
|
||||
import "io"
|
||||
|
@ -1,4 +1,4 @@
|
||||
package codec
|
||||
package tape
|
||||
|
||||
// GBEUSize returns the size (in octets) of a GBEU integer.
|
||||
func GBEUSize(value uint64) int {
|
@ -1,4 +1,4 @@
|
||||
package codec
|
||||
package tape
|
||||
|
||||
import "testing"
|
||||
|
@ -1,7 +1,5 @@
|
||||
package tape
|
||||
|
||||
import "git.tebibyte.media/sashakoshka/hopp/codec"
|
||||
|
||||
type Tag byte; const (
|
||||
SI Tag = 0 << 5 // Small integer
|
||||
LI Tag = 1 << 5 // Large integer
|
||||
@ -40,6 +38,6 @@ func bufferLenTag(length int) Tag {
|
||||
if length < int(CNLimit) {
|
||||
return SBA.WithCN(length)
|
||||
} else {
|
||||
return LBA.WithCN(codec.IntBytes(uint64(length)))
|
||||
return LBA.WithCN(IntBytes(uint64(length)))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user