Files
moxa/stdlib/go1_16_encoding_binary.go
Marc Vertes e56db3b82e interp: improve interface wrappers when used by reflect
When an interpreter type implementing an interface is
used by the runtime, the runtime can extract its type
and create new values using reflect, and call methods
on it. The problem is that there will be no interpreted
method counterpart in this case, which makes wrapper panic.

Allow the String() method wrapper to always succeed and
return an empty string if no interpreted method is present.

This allows scripts to define custom flag.Value types on
which the runtime internally instantiates values using
reflect (see isZeroValue in Go src/flag/flag.go).

This workaround could be generalized to all wrappers if
necessary. At this moment, it is convenient to keep the
default behavior of expecting instantiated interpreter
methods, in order to catch interpreter bugs related to
interfaces.

Fixes #1276.
2021-10-08 15:56:06 +02:00

76 lines
2.3 KiB
Go

// Code generated by 'yaegi extract encoding/binary'. DO NOT EDIT.
// +build go1.16,!go1.17
package stdlib
import (
"encoding/binary"
"go/constant"
"go/token"
"reflect"
)
func init() {
Symbols["encoding/binary/binary"] = map[string]reflect.Value{
// function, constant and variable definitions
"BigEndian": reflect.ValueOf(&binary.BigEndian).Elem(),
"LittleEndian": reflect.ValueOf(&binary.LittleEndian).Elem(),
"MaxVarintLen16": reflect.ValueOf(constant.MakeFromLiteral("3", token.INT, 0)),
"MaxVarintLen32": reflect.ValueOf(constant.MakeFromLiteral("5", token.INT, 0)),
"MaxVarintLen64": reflect.ValueOf(constant.MakeFromLiteral("10", token.INT, 0)),
"PutUvarint": reflect.ValueOf(binary.PutUvarint),
"PutVarint": reflect.ValueOf(binary.PutVarint),
"Read": reflect.ValueOf(binary.Read),
"ReadUvarint": reflect.ValueOf(binary.ReadUvarint),
"ReadVarint": reflect.ValueOf(binary.ReadVarint),
"Size": reflect.ValueOf(binary.Size),
"Uvarint": reflect.ValueOf(binary.Uvarint),
"Varint": reflect.ValueOf(binary.Varint),
"Write": reflect.ValueOf(binary.Write),
// type definitions
"ByteOrder": reflect.ValueOf((*binary.ByteOrder)(nil)),
// interface wrapper definitions
"_ByteOrder": reflect.ValueOf((*_encoding_binary_ByteOrder)(nil)),
}
}
// _encoding_binary_ByteOrder is an interface wrapper for ByteOrder type
type _encoding_binary_ByteOrder struct {
IValue interface{}
WPutUint16 func(a0 []byte, a1 uint16)
WPutUint32 func(a0 []byte, a1 uint32)
WPutUint64 func(a0 []byte, a1 uint64)
WString func() string
WUint16 func(a0 []byte) uint16
WUint32 func(a0 []byte) uint32
WUint64 func(a0 []byte) uint64
}
func (W _encoding_binary_ByteOrder) PutUint16(a0 []byte, a1 uint16) {
W.WPutUint16(a0, a1)
}
func (W _encoding_binary_ByteOrder) PutUint32(a0 []byte, a1 uint32) {
W.WPutUint32(a0, a1)
}
func (W _encoding_binary_ByteOrder) PutUint64(a0 []byte, a1 uint64) {
W.WPutUint64(a0, a1)
}
func (W _encoding_binary_ByteOrder) String() string {
if W.WString == nil {
return ""
}
return W.WString()
}
func (W _encoding_binary_ByteOrder) Uint16(a0 []byte) uint16 {
return W.WUint16(a0)
}
func (W _encoding_binary_ByteOrder) Uint32(a0 []byte) uint32 {
return W.WUint32(a0)
}
func (W _encoding_binary_ByteOrder) Uint64(a0 []byte) uint64 {
return W.WUint64(a0)
}