Module: stdgo.encoding.binary
Overview
Package binary implements simple translation between numbers and byte sequences and encoding and decoding of varints.
Numbers are translated by reading and writing fixed-size values. A fixed-size value is either a fixed-size arithmetic type (bool, int8, uint8, int16, float32, complex64, ...) or an array or struct containing only fixed-size values.
The varint functions encode and decode single integer values using a variable-length encoding; smaller values require fewer bytes. For a specification, see https://developers.google.com/protocol-buffers/docs/encoding.
This package favors simplicity over efficiency. Clients that require high-performance serialization, especially for large data structures, should look at more advanced solutions such as the encoding/gob package or protocol buffers.
Index
-
function _testConstant(_t:stdgo.Ref<stdgo.testing.T_>, _w:stdgo.GoUInt, _max:stdgo.GoInt):Void
-
function _testUvarint(_t:stdgo.Ref<stdgo.testing.T_>, _x:stdgo.GoUInt64):Void
-
function _testVarint(_t:stdgo.Ref<stdgo.testing.T_>, _x:stdgo.GoInt64):Void
-
function appendUvarint(_buf:stdgo.Slice<stdgo.GoByte>, _x:stdgo.GoUInt64):stdgo.Slice<stdgo.GoByte>
-
function appendVarint(_buf:stdgo.Slice<stdgo.GoByte>, _x:stdgo.GoInt64):stdgo.Slice<stdgo.GoByte>
-
function benchmarkAppendUint16(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkAppendUint32(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkAppendUint64(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkLittleEndianAppendUint16(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkLittleEndianAppendUint32(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkLittleEndianAppendUint64(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkLittleEndianPutUint16(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkLittleEndianPutUint32(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkLittleEndianPutUint64(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkPutUint16(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkPutUint32(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkPutUint64(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkPutUvarint32(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkPutUvarint64(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkReadFloats(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkReadInts(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkReadSlice1000Float32s(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkReadSlice1000Int32s(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkReadSlice1000Uint8s(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkReadStruct(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkWriteFloats(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkWriteInts(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkWriteSlice1000Float32s(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkWriteSlice1000Int32s(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkWriteSlice1000Uint8s(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkWriteStruct(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function putUvarint(_buf:stdgo.Slice<stdgo.GoByte>, _x:stdgo.GoUInt64):stdgo.GoInt
-
function putVarint(_buf:stdgo.Slice<stdgo.GoByte>, _x:stdgo.GoInt64):stdgo.GoInt
-
function readUvarint(_r:stdgo.io.ByteReader):{ _1:stdgo.Error; _0:stdgo.GoUInt64; }
-
function readVarint(_r:stdgo.io.ByteReader):{ _1:stdgo.Error; _0:stdgo.GoInt64; }
-
function testBigEndianPtrWrite(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testBigEndianRead(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testBigEndianWrite(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testBlankFields(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testBufferTooBigWithOverflow(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testBufferTooSmall(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testEarlyBoundsChecks(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testLittleEndianPtrWrite(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testLittleEndianRead(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testLittleEndianWrite(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testNativeEndian(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testNoFixedSize(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testNonCanonicalZero(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testReadBoolSlice(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testReadErrorMsg(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testReadInvalidDestination(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testReadTruncated(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testSizeInvalid(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testSizeStructCache(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testSliceRoundTrip(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testUnexportedRead(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testWriteSlice(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function uvarint(_buf:stdgo.Slice<stdgo.GoByte>):{ _1:stdgo.GoInt; _0:stdgo.GoUInt64; }
-
function varint(_buf:stdgo.Slice<stdgo.GoByte>):{ _1:stdgo.GoInt; _0:stdgo.GoInt64; }
-
function new(?age:stdgo.GoInt, ?weight:stdgo.GoFloat64, ?height:stdgo.GoFloat64):Void
Examples
Constants
import stdgo.encoding.binary.Binary
final maxVarintLen16:stdgo.GoUInt64 = ((3i64 : stdgo.GoUInt64))
MaxVarintLenN is the maximum length of a varint-encoded N-bit integer.
final maxVarintLen32:stdgo.GoUInt64 = ((5i64 : stdgo.GoUInt64))
MaxVarintLenN is the maximum length of a varint-encoded N-bit integer.
final maxVarintLen64:stdgo.GoUInt64 = ((10i64 : stdgo.GoUInt64))
MaxVarintLenN is the maximum length of a varint-encoded N-bit integer.
Variables
import stdgo.encoding.binary.Binary
var _big:stdgo.Slice<stdgo.GoUInt8>
var _errOverflow:stdgo.Error
var _intArrays:stdgo.Slice<stdgo.AnyInterface>
Addresses of arrays are easier to manipulate with reflection than are slices.
var _little:stdgo.Slice<stdgo.GoUInt8>
var _putbuf:stdgo.Slice<stdgo.GoUInt8>
var _res:stdgo.Slice<stdgo.GoInt32>
var _s:stdgo.encoding.binary.Struct
var _src:stdgo.Slice<stdgo.GoUInt8>
var _structSize:stdgo.sync.Map_
map[reflect.Type]int
var _tests:stdgo.Slice<stdgo.GoInt64>
var bigEndian:stdgo.encoding.binary.T_bigEndian
BigEndian is the big-endian implementation of ByteOrder and AppendByteOrder.
var littleEndian:stdgo.encoding.binary.T_littleEndian
LittleEndian is the little-endian implementation of ByteOrder and AppendByteOrder.
var nativeEndian:stdgo.encoding.binary.T_nativeEndian
NativeEndian is the native-endian implementation of ByteOrder and AppendByteOrder.
Functions
import stdgo.encoding.binary.Binary
function _checkResult
function _checkResult(_t:stdgo.Ref<stdgo.testing.T_>, _dir:stdgo.GoString, _order:stdgo.encoding.binary.ByteOrder, _err:stdgo.Error, _have:stdgo.AnyInterface, _want:stdgo.AnyInterface):Void
function _dataSize
function _dataSize(_v:stdgo.reflect.Value):stdgo.GoInt
dataSize returns the number of bytes the actual data represented by v occupies in memory. For compound structures, it sums the sizes of the elements. Thus, for instance, for a slice it returns the length of the slice times the element size and does not count the memory occupied by the header. If the type of v is not acceptable, dataSize returns -1.
function _intDataSize
function _intDataSize(_data:stdgo.AnyInterface):stdgo.GoInt
intDataSize returns the size of the data required to represent the data when encoded. It returns zero if the type cannot be implemented by the fast path in Read or Write.
function _sizeof
function _sizeof(_t:stdgo.reflect.Type_):stdgo.GoInt
sizeof returns the size \>= 0 of variables for the given type or -1 if the type is not acceptable.
function _testConstant
function _testConstant(_t:stdgo.Ref<stdgo.testing.T_>, _w:stdgo.GoUInt, _max:stdgo.GoInt):Void
function _testOverflow
function _testOverflow(_t:stdgo.Ref<stdgo.testing.T_>, _buf:stdgo.Slice<stdgo.GoByte>, _x0:stdgo.GoUInt64, _n0:stdgo.GoInt, _err0:stdgo.Error):Void
function _testPutUint64SmallSliceLengthPanics
function _testPutUint64SmallSliceLengthPanics():Bool
function _testRead
function _testRead(_t:stdgo.Ref<stdgo.testing.T_>, _order:stdgo.encoding.binary.ByteOrder, _b:stdgo.Slice<stdgo.GoByte>, _s1:stdgo.AnyInterface):Void
function _testReadInvalidDestination
function _testReadInvalidDestination(_t:stdgo.Ref<stdgo.testing.T_>, _order:stdgo.encoding.binary.ByteOrder):Void
function _testUint64SmallSliceLengthPanics
function _testUint64SmallSliceLengthPanics():Bool
function _testUvarint
function _testUvarint(_t:stdgo.Ref<stdgo.testing.T_>, _x:stdgo.GoUInt64):Void
function _testVarint
function _testVarint(_t:stdgo.Ref<stdgo.testing.T_>, _x:stdgo.GoInt64):Void
function _testWrite
function _testWrite(_t:stdgo.Ref<stdgo.testing.T_>, _order:stdgo.encoding.binary.ByteOrder, _b:stdgo.Slice<stdgo.GoByte>, _s1:stdgo.AnyInterface):Void
function appendUvarint
function appendUvarint(_buf:stdgo.Slice<stdgo.GoByte>, _x:stdgo.GoUInt64):stdgo.Slice<stdgo.GoByte>
AppendUvarint appends the varint-encoded form of x, as generated by PutUvarint, to buf and returns the extended buffer.
function appendVarint
function appendVarint(_buf:stdgo.Slice<stdgo.GoByte>, _x:stdgo.GoInt64):stdgo.Slice<stdgo.GoByte>
AppendVarint appends the varint-encoded form of x, as generated by PutVarint, to buf and returns the extended buffer.
function benchmarkAppendUint16
function benchmarkAppendUint16(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkAppendUint32
function benchmarkAppendUint32(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkAppendUint64
function benchmarkAppendUint64(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkLittleEndianAppendUint16
function benchmarkLittleEndianAppendUint16(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkLittleEndianAppendUint32
function benchmarkLittleEndianAppendUint32(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkLittleEndianAppendUint64
function benchmarkLittleEndianAppendUint64(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkLittleEndianPutUint16
function benchmarkLittleEndianPutUint16(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkLittleEndianPutUint32
function benchmarkLittleEndianPutUint32(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkLittleEndianPutUint64
function benchmarkLittleEndianPutUint64(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkPutUint16
function benchmarkPutUint16(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkPutUint32
function benchmarkPutUint32(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkPutUint64
function benchmarkPutUint64(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkPutUvarint32
function benchmarkPutUvarint32(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkPutUvarint64
function benchmarkPutUvarint64(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkReadFloats
function benchmarkReadFloats(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkReadInts
function benchmarkReadInts(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkReadSlice1000Float32s
function benchmarkReadSlice1000Float32s(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkReadSlice1000Int32s
function benchmarkReadSlice1000Int32s(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkReadSlice1000Uint8s
function benchmarkReadSlice1000Uint8s(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkReadStruct
function benchmarkReadStruct(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkWriteFloats
function benchmarkWriteFloats(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkWriteInts
function benchmarkWriteInts(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkWriteSlice1000Float32s
function benchmarkWriteSlice1000Float32s(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkWriteSlice1000Int32s
function benchmarkWriteSlice1000Int32s(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkWriteSlice1000Uint8s
function benchmarkWriteSlice1000Uint8s(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkWriteStruct
function benchmarkWriteStruct(_b:stdgo.Ref<stdgo.testing.B>):Void
function putUvarint
function putUvarint(_buf:stdgo.Slice<stdgo.GoByte>, _x:stdgo.GoUInt64):stdgo.GoInt
PutUvarint encodes a uint64 into buf and returns the number of bytes written. If the buffer is too small, PutUvarint will panic.
examplePutUvarint
function examplePutUvarint():Void {
var _buf = new stdgo.Slice<stdgo.GoUInt8>((10 : stdgo.GoInt).toBasic(), 0).__setNumber32__();
for (__0 => _x in (new stdgo.Slice<stdgo.GoUInt64>(6, 6, (1i64 : stdgo.GoUInt64), (2i64 : stdgo.GoUInt64), (127i64 : stdgo.GoUInt64), (128i64 : stdgo.GoUInt64), (255i64 : stdgo.GoUInt64), (256i64 : stdgo.GoUInt64)) : stdgo.Slice<stdgo.GoUInt64>)) {
var _n:stdgo.GoInt = stdgo.encoding.binary.Binary.putUvarint(_buf, _x);
stdgo.fmt.Fmt.printf(("%x\n" : stdgo.GoString), stdgo.Go.toInterface((_buf.__slice__(0, _n) : stdgo.Slice<stdgo.GoUInt8>)));
};
}
function putVarint
function putVarint(_buf:stdgo.Slice<stdgo.GoByte>, _x:stdgo.GoInt64):stdgo.GoInt
PutVarint encodes an int64 into buf and returns the number of bytes written. If the buffer is too small, PutVarint will panic.
examplePutVarint
function examplePutVarint():Void {
var _buf = new stdgo.Slice<stdgo.GoUInt8>((10 : stdgo.GoInt).toBasic(), 0).__setNumber32__();
for (__0 => _x in (new stdgo.Slice<stdgo.GoInt64>(
9,
9,
(-65i64 : stdgo.GoInt64),
(-64i64 : stdgo.GoInt64),
(-2i64 : stdgo.GoInt64),
(-1i64 : stdgo.GoInt64),
(0i64 : stdgo.GoInt64),
(1i64 : stdgo.GoInt64),
(2i64 : stdgo.GoInt64),
(63i64 : stdgo.GoInt64),
(64i64 : stdgo.GoInt64)) : stdgo.Slice<stdgo.GoInt64>)) {
var _n:stdgo.GoInt = stdgo.encoding.binary.Binary.putVarint(_buf, _x);
stdgo.fmt.Fmt.printf(("%x\n" : stdgo.GoString), stdgo.Go.toInterface((_buf.__slice__(0, _n) : stdgo.Slice<stdgo.GoUInt8>)));
};
}
function read
function read(_r:stdgo.io.Reader, _order:stdgo.encoding.binary.ByteOrder, _data:stdgo.AnyInterface):stdgo.Error
Read reads structured binary data from r into data. Data must be a pointer to a fixed-size value or a slice of fixed-size values. Bytes read from r are decoded using the specified byte order and written to successive fields of the data. When decoding boolean values, a zero byte is decoded as false, and any other non-zero byte is decoded as true. When reading into structs, the field data for fields with blank (_) field names is skipped; i.e., blank field names may be used for padding. When reading into a struct, all non-blank fields must be exported or Read may panic.
The error is EOF only if no bytes were read. If an EOF happens after reading some but not all the bytes, Read returns ErrUnexpectedEOF.
exampleRead
function exampleRead():Void {
var _pi:stdgo.GoFloat64 = (0 : stdgo.GoFloat64);
var _b = (new stdgo.Slice<stdgo.GoUInt8>(8, 8, (24 : stdgo.GoUInt8), (45 : stdgo.GoUInt8), (68 : stdgo.GoUInt8), (84 : stdgo.GoUInt8), (251 : stdgo.GoUInt8), (33 : stdgo.GoUInt8), (9 : stdgo.GoUInt8), (64 : stdgo.GoUInt8)) : stdgo.Slice<stdgo.GoUInt8>);
var _buf = stdgo.bytes.Bytes.newReader(_b);
var _err:stdgo.Error = stdgo.encoding.binary.Binary.read(stdgo.Go.asInterface(_buf), stdgo.Go.asInterface(stdgo.encoding.binary.Binary.littleEndian), stdgo.Go.toInterface(stdgo.Go.pointer(_pi)));
if (_err != null) {
stdgo.fmt.Fmt.println(stdgo.Go.toInterface(("binary.Read failed:" : stdgo.GoString)), stdgo.Go.toInterface(_err));
};
stdgo.fmt.Fmt.print(stdgo.Go.toInterface(_pi));
}
exampleRead_multi
function exampleRead_multi():Void {
var _b = (new stdgo.Slice<stdgo.GoUInt8>(
14,
14,
(24 : stdgo.GoUInt8),
(45 : stdgo.GoUInt8),
(68 : stdgo.GoUInt8),
(84 : stdgo.GoUInt8),
(251 : stdgo.GoUInt8),
(33 : stdgo.GoUInt8),
(9 : stdgo.GoUInt8),
(64 : stdgo.GoUInt8),
(255 : stdgo.GoUInt8),
(1 : stdgo.GoUInt8),
(2 : stdgo.GoUInt8),
(3 : stdgo.GoUInt8),
(190 : stdgo.GoUInt8),
(239 : stdgo.GoUInt8)) : stdgo.Slice<stdgo.GoUInt8>);
var _r = stdgo.bytes.Bytes.newReader(_b);
var _data:T__struct_7 = ({ pi : (0 : stdgo.GoFloat64), uate : (0 : stdgo.GoUInt8), mine : new stdgo.GoArray<stdgo.GoUInt8>(...[for (i in 0 ... 3) (0 : stdgo.GoUInt8)]), too : (0 : stdgo.GoUInt16) } : T__struct_7);
{
var _err:stdgo.Error = stdgo.encoding.binary.Binary.read(stdgo.Go.asInterface(_r), stdgo.Go.asInterface(stdgo.encoding.binary.Binary.littleEndian), stdgo.Go.toInterface(stdgo.Go.asInterface((stdgo.Go.setRef(_data) : stdgo.Ref<T__struct_7>))));
if (_err != null) {
stdgo.fmt.Fmt.println(stdgo.Go.toInterface(("binary.Read failed:" : stdgo.GoString)), stdgo.Go.toInterface(_err));
};
};
stdgo.fmt.Fmt.println(stdgo.Go.toInterface(_data.pi));
stdgo.fmt.Fmt.println(stdgo.Go.toInterface(_data.uate));
stdgo.fmt.Fmt.printf(("% x\n" : stdgo.GoString), stdgo.Go.toInterface(_data.mine));
stdgo.fmt.Fmt.println(stdgo.Go.toInterface(_data.too));
}
function readUvarint
function readUvarint(_r:stdgo.io.ByteReader):{
_1:stdgo.Error;
_0:stdgo.GoUInt64;
}
ReadUvarint reads an encoded unsigned integer from r and returns it as a uint64. The error is EOF only if no bytes were read. If an EOF happens after reading some but not all the bytes, ReadUvarint returns io.ErrUnexpectedEOF.
function readVarint
function readVarint(_r:stdgo.io.ByteReader):{
_1:stdgo.Error;
_0:stdgo.GoInt64;
}
ReadVarint reads an encoded signed integer from r and returns it as an int64. The error is EOF only if no bytes were read. If an EOF happens after reading some but not all the bytes, ReadVarint returns io.ErrUnexpectedEOF.
function size
function size(_v:stdgo.AnyInterface):stdgo.GoInt
Size returns how many bytes Write would generate to encode the value v, which must be a fixed-size value or a slice of fixed-size values, or a pointer to such data. If v is neither of these, Size returns -1.
function testBigEndianPtrWrite
function testBigEndianPtrWrite(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testBigEndianRead
function testBigEndianRead(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testBigEndianWrite
function testBigEndianWrite(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testBlankFields
function testBlankFields(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testBufferTooBigWithOverflow
function testBufferTooBigWithOverflow(_t:stdgo.Ref<stdgo.testing.T_>):Void
Ensure that we catch overflows of bytes going past MaxVarintLen64. See issue https://golang.org/issues/41185
function testBufferTooSmall
function testBufferTooSmall(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testByteOrder
function testByteOrder(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testConstants
function testConstants(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testEarlyBoundsChecks
function testEarlyBoundsChecks(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testLittleEndianPtrWrite
function testLittleEndianPtrWrite(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testLittleEndianRead
function testLittleEndianRead(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testLittleEndianWrite
function testLittleEndianWrite(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testNativeEndian
function testNativeEndian(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testNoFixedSize
function testNoFixedSize(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testNonCanonicalZero
function testNonCanonicalZero(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testOverflow
function testOverflow(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testReadBool
function testReadBool(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testReadBoolSlice
function testReadBoolSlice(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testReadErrorMsg
function testReadErrorMsg(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testReadInvalidDestination
function testReadInvalidDestination(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testReadSlice
function testReadSlice(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testReadTruncated
function testReadTruncated(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testSizeInvalid
function testSizeInvalid(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testSizeStructCache
function testSizeStructCache(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testSliceRoundTrip
function testSliceRoundTrip(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testUnexportedRead
function testUnexportedRead(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testUvarint
function testUvarint(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testVarint
function testVarint(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testWriteSlice
function testWriteSlice(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testWriteT
function testWriteT(_t:stdgo.Ref<stdgo.testing.T_>):Void
function uvarint
function uvarint(_buf:stdgo.Slice<stdgo.GoByte>):{
_1:stdgo.GoInt;
_0:stdgo.GoUInt64;
}
Uvarint decodes a uint64 from buf and returns that value and the number of bytes read (\> 0). If an error occurred, the value is 0 and the number of bytes n is \<= 0 meaning:
n == 0: buf too small
n < 0: value larger than 64 bits (overflow)
and -n is the number of bytes read
exampleUvarint
function exampleUvarint():Void {
var _inputs = (new stdgo.Slice<stdgo.Slice<stdgo.GoUInt8>>(6, 6, (new stdgo.Slice<stdgo.GoUInt8>(1, 1, (1 : stdgo.GoUInt8)) : stdgo.Slice<stdgo.GoUInt8>), (new stdgo.Slice<stdgo.GoUInt8>(1, 1, (2 : stdgo.GoUInt8)) : stdgo.Slice<stdgo.GoUInt8>), (new stdgo.Slice<stdgo.GoUInt8>(1, 1, (127 : stdgo.GoUInt8)) : stdgo.Slice<stdgo.GoUInt8>), (new stdgo.Slice<stdgo.GoUInt8>(2, 2, (128 : stdgo.GoUInt8), (1 : stdgo.GoUInt8)) : stdgo.Slice<stdgo.GoUInt8>), (new stdgo.Slice<stdgo.GoUInt8>(2, 2, (255 : stdgo.GoUInt8), (1 : stdgo.GoUInt8)) : stdgo.Slice<stdgo.GoUInt8>), (new stdgo.Slice<stdgo.GoUInt8>(2, 2, (128 : stdgo.GoUInt8), (2 : stdgo.GoUInt8)) : stdgo.Slice<stdgo.GoUInt8>)) : stdgo.Slice<stdgo.Slice<stdgo.GoUInt8>>);
for (__0 => _b in _inputs) {
var __tmp__ = stdgo.encoding.binary.Binary.uvarint(_b), _x:stdgo.GoUInt64 = __tmp__._0, _n:stdgo.GoInt = __tmp__._1;
if (_n != ((_b.length))) {
stdgo.fmt.Fmt.println(stdgo.Go.toInterface(("Uvarint did not consume all of in" : stdgo.GoString)));
};
stdgo.fmt.Fmt.println(stdgo.Go.toInterface(_x));
};
}
function varint
function varint(_buf:stdgo.Slice<stdgo.GoByte>):{
_1:stdgo.GoInt;
_0:stdgo.GoInt64;
}
Varint decodes an int64 from buf and returns that value and the number of bytes read (\> 0). If an error occurred, the value is 0 and the number of bytes n is \<= 0 with the following meaning:
n == 0: buf too small
n < 0: value larger than 64 bits (overflow)
and -n is the number of bytes read
exampleVarint
function exampleVarint():Void {
var _inputs = (new stdgo.Slice<stdgo.Slice<stdgo.GoUInt8>>(
9,
9,
(new stdgo.Slice<stdgo.GoUInt8>(2, 2, (129 : stdgo.GoUInt8), (1 : stdgo.GoUInt8)) : stdgo.Slice<stdgo.GoUInt8>),
(new stdgo.Slice<stdgo.GoUInt8>(1, 1, (127 : stdgo.GoUInt8)) : stdgo.Slice<stdgo.GoUInt8>),
(new stdgo.Slice<stdgo.GoUInt8>(1, 1, (3 : stdgo.GoUInt8)) : stdgo.Slice<stdgo.GoUInt8>),
(new stdgo.Slice<stdgo.GoUInt8>(1, 1, (1 : stdgo.GoUInt8)) : stdgo.Slice<stdgo.GoUInt8>),
(new stdgo.Slice<stdgo.GoUInt8>(1, 1, (0 : stdgo.GoUInt8)) : stdgo.Slice<stdgo.GoUInt8>),
(new stdgo.Slice<stdgo.GoUInt8>(1, 1, (2 : stdgo.GoUInt8)) : stdgo.Slice<stdgo.GoUInt8>),
(new stdgo.Slice<stdgo.GoUInt8>(1, 1, (4 : stdgo.GoUInt8)) : stdgo.Slice<stdgo.GoUInt8>),
(new stdgo.Slice<stdgo.GoUInt8>(1, 1, (126 : stdgo.GoUInt8)) : stdgo.Slice<stdgo.GoUInt8>),
(new stdgo.Slice<stdgo.GoUInt8>(2, 2, (128 : stdgo.GoUInt8), (1 : stdgo.GoUInt8)) : stdgo.Slice<stdgo.GoUInt8>)) : stdgo.Slice<stdgo.Slice<stdgo.GoUInt8>>);
for (__0 => _b in _inputs) {
var __tmp__ = stdgo.encoding.binary.Binary.varint(_b), _x:stdgo.GoInt64 = __tmp__._0, _n:stdgo.GoInt = __tmp__._1;
if (_n != ((_b.length))) {
stdgo.fmt.Fmt.println(stdgo.Go.toInterface(("Varint did not consume all of in" : stdgo.GoString)));
};
stdgo.fmt.Fmt.println(stdgo.Go.toInterface(_x));
};
}
function write
function write(_w:stdgo.io.Writer, _order:stdgo.encoding.binary.ByteOrder, _data:stdgo.AnyInterface):stdgo.Error
Write writes the binary representation of data into w. Data must be a fixed-size value or a slice of fixed-size values, or a pointer to such data. Boolean values encode as one byte: 1 for true, and 0 for false. Bytes written to w are encoded using the specified byte order and read from successive fields of the data. When writing structs, zero values are written for fields with blank (_) field names.
exampleWrite
function exampleWrite():Void {
var _buf = (stdgo.Go.setRef(({} : stdgo.bytes.Bytes.Buffer)) : stdgo.Ref<stdgo.bytes.Bytes.Buffer>);
var _pi:stdgo.GoFloat64 = (3.141592653589793 : stdgo.GoFloat64);
var _err:stdgo.Error = stdgo.encoding.binary.Binary.write(stdgo.Go.asInterface(_buf), stdgo.Go.asInterface(stdgo.encoding.binary.Binary.littleEndian), stdgo.Go.toInterface(_pi));
if (_err != null) {
stdgo.fmt.Fmt.println(stdgo.Go.toInterface(("binary.Write failed:" : stdgo.GoString)), stdgo.Go.toInterface(_err));
};
stdgo.fmt.Fmt.printf(("% x" : stdgo.GoString), stdgo.Go.toInterface(_buf.bytes()));
}
exampleWrite_multi
function exampleWrite_multi():Void {
var _buf = (stdgo.Go.setRef(({} : stdgo.bytes.Bytes.Buffer)) : stdgo.Ref<stdgo.bytes.Bytes.Buffer>);
var _data:stdgo.Slice<stdgo.AnyInterface> = (new stdgo.Slice<stdgo.AnyInterface>(3, 3, stdgo.Go.toInterface((61374 : stdgo.GoUInt16)), stdgo.Go.toInterface((-54 : stdgo.GoInt8)), stdgo.Go.toInterface((254 : stdgo.GoUInt8))) : stdgo.Slice<stdgo.AnyInterface>);
for (__0 => _v in _data) {
var _err:stdgo.Error = stdgo.encoding.binary.Binary.write(stdgo.Go.asInterface(_buf), stdgo.Go.asInterface(stdgo.encoding.binary.Binary.littleEndian), _v);
if (_err != null) {
stdgo.fmt.Fmt.println(stdgo.Go.toInterface(("binary.Write failed:" : stdgo.GoString)), stdgo.Go.toInterface(_err));
};
};
stdgo.fmt.Fmt.printf(("%x" : stdgo.GoString), stdgo.Go.toInterface(_buf.bytes()));
}
Classes
import stdgo.encoding.binary.*
class BlankFields
var __4:stdgo.GoInt32
var __5:stdgo.GoArray<stdgo.GoInt16>
var __6:stdgo.GoArray<stdgo.GoUInt8>
var __7:{
_f:stdgo.GoArray<stdgo.GoFloat32>;
}
var a:stdgo.GoUInt32
var b:stdgo.GoFloat64
var c:stdgo.GoUInt8
BlankFields function new
function new(?a:stdgo.GoUInt32, ?__4:stdgo.GoInt32, ?b:stdgo.GoFloat64, ?__5:stdgo.GoArray<stdgo.GoInt16>, ?c:stdgo.GoUInt8, ?__6:stdgo.GoArray<stdgo.GoUInt8>, ?__7:{
_f:stdgo.GoArray<stdgo.GoFloat32>;
}):Void
class BlankFieldsProbe
var a:stdgo.GoUInt32
var b:stdgo.GoFloat64
var c:stdgo.GoUInt8
var p0:stdgo.GoInt32
var p1:stdgo.GoArray<stdgo.GoInt16>
var p2:stdgo.GoArray<stdgo.GoUInt8>
var p3:{
():stdgo.GoArray<stdgo.GoFloat32>;
}
BlankFieldsProbe function new
function new(?a:stdgo.GoUInt32, ?p0:stdgo.GoInt32, ?b:stdgo.GoFloat64, ?p1:stdgo.GoArray<stdgo.GoInt16>, ?c:stdgo.GoUInt8, ?p2:stdgo.GoArray<stdgo.GoUInt8>, ?p3:{
():stdgo.GoArray<stdgo.GoFloat32>;
}):Void
class Struct
var array:stdgo.GoArray<stdgo.GoUInt8>
var boolArray:stdgo.GoArray<Bool>
var bool_:Bool
var complex128:stdgo.GoComplex128
var complex64:stdgo.GoComplex64
var float32:stdgo.GoFloat32
var float64:stdgo.GoFloat64
var int16:stdgo.GoInt16
var int32:stdgo.GoInt32
var int64:stdgo.GoInt64
var int8:stdgo.GoInt8
var uint16:stdgo.GoUInt16
var uint32:stdgo.GoUInt32
var uint64:stdgo.GoUInt64
var uint8:stdgo.GoUInt8
Struct function new
function new(?int8:stdgo.GoInt8, ?int16:stdgo.GoInt16, ?int32:stdgo.GoInt32, ?int64:stdgo.GoInt64, ?uint8:stdgo.GoUInt8, ?uint16:stdgo.GoUInt16, ?uint32:stdgo.GoUInt32, ?uint64:stdgo.GoUInt64, ?float32:stdgo.GoFloat32, ?float64:stdgo.GoFloat64, ?complex64:stdgo.GoComplex64, ?complex128:stdgo.GoComplex128, ?array:stdgo.GoArray<stdgo.GoUInt8>, ?bool_:Bool, ?boolArray:stdgo.GoArray<Bool>):Void
class T_
var array:stdgo.GoArray<stdgo.GoInt>
var int_:stdgo.GoInt
var uint:stdgo.GoUInt
var uintptr:stdgo.GoUIntptr
T_ function new
function new(?int_:stdgo.GoInt, ?uint:stdgo.GoUInt, ?uintptr:stdgo.GoUIntptr, ?array:stdgo.GoArray<stdgo.GoInt>):Void
class T\testNoFixedSize\14\\\localname\__Person
var age:stdgo.GoInt
var height:stdgo.GoFloat64
var weight:stdgo.GoFloat64
T\testNoFixedSize\14\\\localname\__Person function new
function new(?age:stdgo.GoInt, ?weight:stdgo.GoFloat64, ?height:stdgo.GoFloat64):Void
class T\testSizeStructCache\11\\\localname\__foo
var a:stdgo.GoUInt32
T\testSizeStructCache\11\\\localname\__foo function new
function new(?a:stdgo.GoUInt32):Void
class T\testSizeStructCache\12\\\localname\__bar
var a:stdgo.encoding.binary.Struct
var b:stdgo.encoding.binary.T_testSizeStructCache_11___localname___foo
var c:stdgo.encoding.binary.Struct
T\testSizeStructCache\12\\\localname\__bar function new
function new(?a:stdgo.encoding.binary.Struct, ?b:stdgo.encoding.binary.T_testSizeStructCache_11___localname___foo, ?c:stdgo.encoding.binary.Struct):Void
class Unexported
var _a:stdgo.GoInt32
Unexported function new
function new(?_a:stdgo.GoInt32):Void
Typedefs
import stdgo.encoding.binary.*
typedef AppendByteOrder
typedef AppendByteOrder = {
public function string():stdgo.GoString;
public function appendUint64(_0:stdgo.Slice<stdgo.GoByte>, _1:stdgo.GoUInt64):stdgo.Slice<stdgo.GoByte>;
public function appendUint32(_0:stdgo.Slice<stdgo.GoByte>, _1:stdgo.GoUInt32):stdgo.Slice<stdgo.GoByte>;
public function appendUint16(_0:stdgo.Slice<stdgo.GoByte>, _1:stdgo.GoUInt16):stdgo.Slice<stdgo.GoByte>;
};
AppendByteOrder specifies how to append 16-, 32-, or 64-bit unsigned integers into a byte slice.
typedef ByteOrder
typedef ByteOrder = {
public function uint64(_0:stdgo.Slice<stdgo.GoByte>):stdgo.GoUInt64;
public function uint32(_0:stdgo.Slice<stdgo.GoByte>):stdgo.GoUInt32;
public function uint16(_0:stdgo.Slice<stdgo.GoByte>):stdgo.GoUInt16;
public function string():stdgo.GoString;
public function putUint64(_0:stdgo.Slice<stdgo.GoByte>, _1:stdgo.GoUInt64):Void;
public function putUint32(_0:stdgo.Slice<stdgo.GoByte>, _1:stdgo.GoUInt32):Void;
public function putUint16(_0:stdgo.Slice<stdgo.GoByte>, _1:stdgo.GoUInt16):Void;
};
A ByteOrder specifies how to convert byte slices into 16-, 32-, or 64-bit unsigned integers.
typedef T__struct_0
typedef T__struct_0 = {
_f:stdgo.GoArray<stdgo.GoFloat32>;
};
typedef T__struct_1
typedef T__struct_1 = {
():stdgo.GoArray<stdgo.GoFloat32>;
};
typedef T__struct_2
typedef T__struct_2 = {
_want:stdgo.GoInt;
_val:stdgo.AnyInterface;
};
typedef T__struct_3
typedef T__struct_3 = {
{
stdgo.encoding.binary.Struct;
};
};
typedef T__struct_4
typedef T__struct_4 = {
};
typedef T__struct_5
typedef T__struct_5 = {
():stdgo.GoFloat64;
<stdgo.GoInt32>;
Dynamic;
<stdgo.GoUInt8>;
b:stdgo.GoUInt8;
{
stdgo.GoUInt8;
};
};
typedef T__struct_6
typedef T__struct_6 = {
_wantValue:stdgo.GoUInt64;
_wantN:stdgo.GoInt;
_name:stdgo.GoString;
_in:stdgo.Slice<stdgo.GoUInt8>;
};
typedef T_decoder
typedef T_decoder = stdgo.encoding.binary.T_coder;
typedef T_encoder
typedef T_encoder = stdgo.encoding.binary.T_coder;
typedef T\testByteOrder\13\\\localname\__byteOrder
typedef T_testByteOrder_13___localname___byteOrder = {
public function uint64(_0:stdgo.Slice<stdgo.GoByte>):stdgo.GoUInt64;
public function uint32(_0:stdgo.Slice<stdgo.GoByte>):stdgo.GoUInt32;
public function uint16(_0:stdgo.Slice<stdgo.GoByte>):stdgo.GoUInt16;
public function string():stdgo.GoString;
public function putUint64(_0:stdgo.Slice<stdgo.GoByte>, _1:stdgo.GoUInt64):Void;
public function putUint32(_0:stdgo.Slice<stdgo.GoByte>, _1:stdgo.GoUInt32):Void;
public function putUint16(_0:stdgo.Slice<stdgo.GoByte>, _1:stdgo.GoUInt16):Void;
public function appendUint64(_0:stdgo.Slice<stdgo.GoByte>, _1:stdgo.GoUInt64):stdgo.Slice<stdgo.GoByte>;
public function appendUint32(_0:stdgo.Slice<stdgo.GoByte>, _1:stdgo.GoUInt32):stdgo.Slice<stdgo.GoByte>;
public function appendUint16(_0:stdgo.Slice<stdgo.GoByte>, _1:stdgo.GoUInt16):stdgo.Slice<stdgo.GoByte>;
};