I wrote a TLV handling package: go.xrfang.cn/tlv 
<https://pkg.go.dev/go.xrfang.cn/tlv>, and encountered problem with type 
checking.  Problematic code below:

1.  The "Set" function in side tlv package:

package tlv

type (
    ValueType interface {
        string | []byte | ~float32 | ~float64 |
        ~int8 | ~int16 | ~int32 | ~int64 |
        ~uint8 | ~uint16 | ~uint32 | ~uint64
    }
    Prop map[byte][]byte
)

func Set[T ValueType](p Prop, tag byte, val T) Prop {
    ... ...
    switch v := any(val).(type) {
    case string:
    ... ...
    default:
        fmt.Printf("tlv.Set: '%T' not supported!\n", val) 
    }
    ...
}

2. event.go, which uses tlv:

package event

import (
"go.xrfang.cn/tlv"
)

type (
Class byte
Event struct {
tlv.Prop
}
)

const (
TagClass  = 3
)

func (e *Event) WithClass(cls Class) *Event {
(*e).Prop = tlv.Set((*e).Prop, TagClass, cls)
return e
}

The problem is, while the Class type is based on "byte", it should be 
accepted by tlv.Set(), which is the case (there is no compiler error).  But 
when the code is running, it printed error message: tlv.Set: 'event.Class' 
not supported!

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/b4786988-b9da-44c3-9070-ba718f3be5ban%40googlegroups.com.

Reply via email to