当前位置: 首页>>代码示例>>Golang>>正文


Golang bin.NewDecoder函数代码示例

本文整理汇总了Golang中github.com/tamtam-im/teleport/lib/go/tl/protocol/bin.NewDecoder函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDecoder函数的具体用法?Golang NewDecoder怎么用?Golang NewDecoder使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewDecoder函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Test_ReadLong

func Test_ReadLong(t *testing.T) {
	data := []byte{0x24, 0x46, 0x49, 0x3c, 0x47, 0x5, 0x2, 0x0}
	var val int64 = 568753465673252

	proto := bin.NewDecoder(bytes.NewBuffer(data))
	res, err := proto.ReadLong()
	assert.NoError(t, err)
	assert.Equal(t, res, val)
}
开发者ID:tamtam-im,项目名称:teleport,代码行数:9,代码来源:input_test.go

示例2: Test_ReadTypeBegin

func Test_ReadTypeBegin(t *testing.T) {
	data := []byte{0x7f, 0x2, 0xe2, 0x5c}
	var val uint32 = 0x5ce2027f

	proto := bin.NewDecoder(bytes.NewBuffer(data))
	res, err := proto.ReadTypeBegin()
	assert.NoError(t, err)
	assert.Equal(t, res, val)
}
开发者ID:tamtam-im,项目名称:teleport,代码行数:9,代码来源:input_test.go

示例3: Test_ReadBytesShort

func Test_ReadBytesShort(t *testing.T) {
	var val string = strings.Repeat("test", 31)
	var data []byte = []byte{0x7c, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x0, 0x0, 0x0}

	proto := bin.NewDecoder(bytes.NewBuffer(data))
	res, err := proto.ReadBytes()
	assert.NoError(t, err)
	assert.Equal(t, val, string(res))
}
开发者ID:tamtam-im,项目名称:teleport,代码行数:9,代码来源:input_test.go

示例4: Test_ReadStringLong

func Test_ReadStringLong(t *testing.T) {
	var val string = strings.Repeat("tes", 101)
	var data []byte = []byte{0xfe, 0x2f, 0x1, 0x0, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x74, 0x65, 0x73, 0x0}

	proto := bin.NewDecoder(bytes.NewBuffer(data))
	res, err := proto.ReadString()
	assert.NoError(t, err)
	assert.Equal(t, val, res)
}
开发者ID:tamtam-im,项目名称:teleport,代码行数:9,代码来源:input_test.go

示例5: Test_ReadDouble

func Test_ReadDouble(t *testing.T) {
	data := []byte{0xbf, 0x7d, 0x1d, 0x38, 0x77, 0x37, 0xb6, 0x40}
	var val float64 = 5687.4657

	proto := bin.NewDecoder(bytes.NewBuffer(data))
	res, err := proto.ReadDouble()
	assert.NoError(t, err)
	assert.Equal(t, res, val)
}
开发者ID:tamtam-im,项目名称:teleport,代码行数:9,代码来源:input_test.go

示例6: Test_ReadInt

func Test_ReadInt(t *testing.T) {
	data := []byte{0x59, 0x1, 0x0, 0x0}
	var val int32 = 345

	proto := bin.NewDecoder(bytes.NewBuffer(data))
	res, err := proto.ReadInt()
	assert.NoError(t, err)
	assert.Equal(t, res, val)
}
开发者ID:tamtam-im,项目名称:teleport,代码行数:9,代码来源:input_test.go

示例7: Test_BytesBoxRead

func Test_BytesBoxRead(t *testing.T) {
	data := []byte{0x9f, 0x37, 0xe1, 0xe, 0x4, 0x74, 0x65, 0x73, 0x74, 0x0, 0x0, 0x0}
	val := builtin.NewBytes([]byte("test"))

	proto := bin.NewDecoder(bytes.NewBuffer(data))

	res := (&builtin.Bytes{}).Box()
	assert.NoError(t, res.Read(proto, nil, uuid.UUID{}))
	assert.Equal(t, val, res.Strip())
}
开发者ID:tamtam-im,项目名称:teleport,代码行数:10,代码来源:box_bytes_test.go

示例8: Test_Bytes_Read

func Test_Bytes_Read(t *testing.T) {
	data := []byte{0x4, 0x74, 0x65, 0x73, 0x74, 0x0, 0x0, 0x0}
	val := []byte("test")

	proto := bin.NewDecoder(bytes.NewBuffer(data))

	res := &builtin.Bytes{}
	assert.NoError(t, res.Read(proto, nil, uuid.UUID{}))
	assert.Equal(t, val, res.Strip().([]byte))
}
开发者ID:tamtam-im,项目名称:teleport,代码行数:10,代码来源:box_bytes_test.go

示例9: Test_IntBoxRead

func Test_IntBoxRead(t *testing.T) {
	data := []byte{0xda, 0x9b, 0x50, 0xa8, 0xda, 0xbc, 0x34, 0x13}
	val := builtin.NewInt(322223322)

	proto := bin.NewDecoder(bytes.NewBuffer(data))

	res := (&builtin.Int{}).Box()
	assert.NoError(t, res.Read(proto, nil, uuid.UUID{}))
	assert.Equal(t, val, res.Strip())
}
开发者ID:tamtam-im,项目名称:teleport,代码行数:10,代码来源:box_int_test.go

示例10: Test_Int_Read

func Test_Int_Read(t *testing.T) {
	data := []byte{0xda, 0xbc, 0x34, 0x13}
	val := int32(322223322)

	proto := bin.NewDecoder(bytes.NewBuffer(data))

	res := &builtin.Int{}
	assert.NoError(t, res.Read(proto, nil, uuid.UUID{}))
	assert.Equal(t, val, res.Strip())
}
开发者ID:tamtam-im,项目名称:teleport,代码行数:10,代码来源:box_int_test.go

示例11: Test_LongBoxRead

func Test_LongBoxRead(t *testing.T) {
	data := []byte{0xba, 0x6c, 0x7, 0x22, 0xda, 0xbc, 0x34, 0x13, 0x0, 0x0, 0x0, 0x0}
	val := builtin.NewLong(322223322)

	proto := bin.NewDecoder(bytes.NewBuffer(data))

	res := (&builtin.Long{}).Box()
	assert.NoError(t, res.Read(proto, nil, uuid.UUID{}))
	assert.Equal(t, val, res.Strip())
}
开发者ID:tamtam-im,项目名称:teleport,代码行数:10,代码来源:box_long_test.go

示例12: Test_DoubleBoxRead

func Test_DoubleBoxRead(t *testing.T) {
	data := []byte{0x54, 0xc1, 0x10, 0x22, 0xef, 0xc9, 0xc3, 0x42, 0x95, 0x77, 0xdf, 0x40}
	val := builtin.NewDouble(32222.3322)

	proto := bin.NewDecoder(bytes.NewBuffer(data))

	res := (&builtin.Double{}).Box()
	assert.NoError(t, res.Read(proto, nil, uuid.UUID{}))
	assert.Equal(t, val, res.Strip())
}
开发者ID:tamtam-im,项目名称:teleport,代码行数:10,代码来源:box_double_test.go

示例13: ReadCheck

func ReadCheck(t *testing.T, expect tl.Bare, data []byte) {
	empty := expect.Box().Empty()
	box := empty.(tl.Box)

	proto := bin.NewDecoder(bytes.NewBuffer(data))
	assert.NoError(t, box.Read(proto, nil, uuid.UUID{}))
	bare, err := box.Bare()
	assert.NoError(t, err)
	assert.EqualValues(t, expect, bare)
}
开发者ID:tamtam-im,项目名称:teleport,代码行数:10,代码来源:utils.go

示例14: Test_Read_SingleMultiIntR4_BadN

func Test_Read_SingleMultiIntR4_BadN(t *testing.T) {
	expect := &mock.SingleMultiInt32R4{}
	data := []byte{
		0xf9, 0x6e, 0xac, 0x3a,
		0x3, 0x0, 0x0, 0x0,
		0x4, 0x0, 0x0, 0x0}
	proto := bin.NewDecoder(bytes.NewBuffer(data))
	err := expect.Box().Read(proto, nil, uuid.UUID{})
	assert.Error(t, err)
}
开发者ID:tamtam-im,项目名称:teleport,代码行数:10,代码来源:multi_read_test.go

示例15: Test_StringBoxRead

func Test_StringBoxRead(t *testing.T) {
	data := []byte{0x24, 0x6e, 0x28, 0xb5, 0x4, 0x74, 0x65, 0x73, 0x74, 0x0, 0x0, 0x0}
	val := builtin.NewString("test")

	proto := bin.NewDecoder(bytes.NewBuffer(data))

	res := (&builtin.String{}).Box()
	assert.NoError(t, res.Read(proto, nil, uuid.UUID{}))
	assert.Equal(t, val, res.Strip())
}
开发者ID:tamtam-im,项目名称:teleport,代码行数:10,代码来源:box_string_test.go


注:本文中的github.com/tamtam-im/teleport/lib/go/tl/protocol/bin.NewDecoder函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。