message-size-increase #3

Merged
sashakoshka merged 227 commits from message-size-increase into main 2025-09-07 19:27:38 -06:00
Showing only changes of commit 3eb826735b - Show all commits

View File

@ -63,53 +63,58 @@ func EncodeAny(encoder *Encoder, value any, tag Tag) (n int, err error) {
// DecodeAny decodes data and places it into destination, which must be a // DecodeAny decodes data and places it into destination, which must be a
// pointer to a supported type. See [EncodeAny] for a list of supported types. // pointer to a supported type. See [EncodeAny] for a list of supported types.
func DecodeAny(decoder *Decoder, destination any, tag Tag) (n int, err error) { func DecodeAny(decoder *Decoder, destination any, tag Tag) (n int, err error) {
return decodeAny(decoder, reflect.ValueOf(destination), tag) reflectDestination := reflect.ValueOf(destination)
if reflectDestination.Kind() != reflect.Pointer {
return n, fmt.Errorf("expected pointer destination, not %v", destination)
}
return decodeAny(decoder, reflectDestination.Elem(), tag)
} }
// unknownSlicePlaceholder is inserted by skeletonValue and informs the program
// that the destination for the slice needs to be generated based on the item
// tag in the OTA.
type unknownSlicePlaceholder struct { }
var unknownSlicePlaceholderType = reflect.TypeOf(unknownSlicePlaceholder { })
// decodeAny is internal to [DecodeAny]. It takes in an addressable
// [reflect.Value] as the destination.
func decodeAny(decoder *Decoder, destination reflect.Value, tag Tag) (n int, err error) { func decodeAny(decoder *Decoder, destination reflect.Value, tag Tag) (n int, err error) {
errWrongDestinationType := func(expected string) error { errWrongDestinationType := func(expected string) error {
// panic(fmt.Errorf( panic(fmt.Errorf(
return fmt.Errorf( // return fmt.Errorf(
"expected %s destination, not %v", "expected %s destination, not %v",
expected, destination) expected, destination))
//)
}
if destination.Kind() != reflect.Pointer {
return n, errWrongDestinationType("pointer")
} }
switch tag.WithoutCN() { switch tag.WithoutCN() {
case SI: case SI:
// SI: (none) // SI: (none)
err = setIntPtr(destination, uint64(tag.CN())) err = setInt(destination, uint64(tag.CN()))
if err != nil { return n, err } if err != nil { return n, err }
case LI: case LI:
// LI: <value: IntN> // LI: <value: IntN>
nn, err := decodeAndSetIntPtr(decoder, destination, tag.CN() + 1) nn, err := decodeAndSetInt(decoder, destination, tag.CN() + 1)
n += nn; if err != nil { return n, err } n += nn; if err != nil { return n, err }
case FP: case FP:
// FP: <value: FloatN> // FP: <value: FloatN>
nn, err := decodeAndSetFloatPtr(decoder, destination, tag.CN() + 1) nn, err := decodeAndSetFloat(decoder, destination, tag.CN() + 1)
n += nn; if err != nil { return n, err } n += nn; if err != nil { return n, err }
case SBA: case SBA:
// SBA: <data: U8>* // SBA: <data: U8>*
destination, err := asByteArrayPtr(destination)
if err != nil { return n, err }
buffer := make([]byte, tag.CN()) buffer := make([]byte, tag.CN())
nn, err := decoder.Read(buffer) nn, err := decoder.Read(buffer)
n += nn; if err != nil { return n, err } n += nn; if err != nil { return n, err }
*destination = buffer err = setByteArray(destination, buffer)
if err != nil { return n, err }
case LBA: case LBA:
// LBA: <length: UN> <data: U8>* // LBA: <length: UN> <data: U8>*
destination, err := asByteArrayPtr(destination)
if err != nil { return n, err }
length, nn, err := decoder.ReadUintN(tag.CN() + 1) length, nn, err := decoder.ReadUintN(tag.CN() + 1)
n += nn; if err != nil { return n, err } n += nn; if err != nil { return n, err }
buffer := make([]byte, length) buffer := make([]byte, length)
nn, err = decoder.Read(buffer) nn, err = decoder.Read(buffer)
n += nn; if err != nil { return n, err } n += nn; if err != nil { return n, err }
*destination = buffer err = setByteArray(destination, buffer)
if err != nil { return n, err }
case OTA: case OTA:
// OTA: <length: UN> <elementTag: tape.Tag> <values>* // OTA: <length: UN> <elementTag: tape.Tag> <values>*
length, nn, err := decoder.ReadUintN(tag.CN() + 1) length, nn, err := decoder.ReadUintN(tag.CN() + 1)