Exemplo n.º 1
0
func (self *Converter) ReadTypeId(input interface{}) bucket.TypeId {
	if input == nil {
		panic("Expecting a type id but value is missing")
	}
	switch input := input.(type) {
	case uint8:
		return bucket.TypeId(input)
	default:
		panic(fmt.Sprintf("Expecting a uint8 or but got a %T", input))
	}
}
Exemplo n.º 2
0
func (self *TypedGetterSetter) TypeId() (typeId bucket.TypeId, err error) {
	binaryValue, err := self.Get(typeIdKey)
	if err != nil {
		return
	}
	if binaryValue == nil || len(binaryValue) == 0 {
		err = errors.New("No type ID stored in metadata")
		return
	}
	var typeIdAsUint8 uint8
	err = encoding.Cbor().Decode(binaryValue, &typeIdAsUint8)
	if err != nil {
		err = errors.New(fmt.Sprintf("Error cbor decoding: %v\n", err))
		return
	}

	return bucket.TypeId(typeIdAsUint8), nil
}