Compare commits
2 Commits
80c7d25c73
...
80161b37f7
Author | SHA1 | Date | |
---|---|---|---|
80161b37f7 | |||
9d40b81e00 |
@ -46,9 +46,16 @@ func EncodeAny(encoder *Encoder, value any, tag Tag) (n int, err error) {
|
||||
case reflect.Uint32: return encoder.WriteUint32(uint32(reflectValue.Uint()))
|
||||
case reflect.Int64: return encoder.WriteInt64(int64(reflectValue.Int()))
|
||||
case reflect.Uint64: return encoder.WriteUint64(uint64(reflectValue.Uint()))
|
||||
case reflect.String: return EncodeAny(encoder, []byte(reflectValue.String()), tag)
|
||||
case reflect.String:
|
||||
if reflectValue.Len() > MaxStructureLength {
|
||||
return 0, ErrTooLong
|
||||
}
|
||||
return EncodeAny(encoder, []byte(reflectValue.String()), tag)
|
||||
}
|
||||
if reflectValue.CanConvert(reflect.TypeOf(dummyBuffer)) {
|
||||
if reflectValue.Len() > MaxStructureLength {
|
||||
return 0, ErrTooLong
|
||||
}
|
||||
if tag.Is(LBA) {
|
||||
nn, err := encoder.WriteUintN(uint64(reflectValue.Len()), tag.CN() + 1)
|
||||
n += nn; if err != nil { return n, err }
|
||||
@ -64,8 +71,13 @@ func EncodeAny(encoder *Encoder, value any, tag Tag) (n int, err error) {
|
||||
case reflect.Slice:
|
||||
return encodeAnySlice(encoder, value, tag)
|
||||
// case reflect.Array:
|
||||
// TODO: we can encode arrays. but can we decode into them?
|
||||
// that's the fucken question. maybe we just do the first
|
||||
// return encodeAnySlice(encoder, reflect.ValueOf(value).Slice(0, reflectType.Len()).Interface(), tag)
|
||||
case reflect.Map:
|
||||
if reflectValue.Len() > MaxStructureLength {
|
||||
return 0, ErrTooLong
|
||||
}
|
||||
if reflectType.Key() == reflect.TypeOf(uint16(0)) {
|
||||
return encodeAnyMap(encoder, value, tag)
|
||||
}
|
||||
|
11
tape/error.go
Normal file
11
tape/error.go
Normal file
@ -0,0 +1,11 @@
|
||||
package tape
|
||||
|
||||
// Error enumerates common errors in this package.
|
||||
type Error string; const (
|
||||
ErrTooLong Error = "data structure too long"
|
||||
)
|
||||
|
||||
// Error implements the error interface.
|
||||
func (err Error) Error() string {
|
||||
return string(err)
|
||||
}
|
13
tape/limits.go
Normal file
13
tape/limits.go
Normal file
@ -0,0 +1,13 @@
|
||||
package tape
|
||||
|
||||
// MaxStructureLength determines how long a TAPE data structure can be. This
|
||||
// applies to:
|
||||
//
|
||||
// - OTA
|
||||
// - SBA/LBA
|
||||
// - KTV
|
||||
//
|
||||
// By default it is set at 2^20 (about a million).
|
||||
// You shouldn't need to change this. If you do, it should only be set once at
|
||||
// the start of the program.
|
||||
var MaxStructureLength = 1024 * 1024
|
Loading…
x
Reference in New Issue
Block a user