예제 #1
0
func TestStreamFrom(t *testing.T) {
	// test reader
	s := stream.NewStreamFrom(numbers)
	testSeekAndReadByte(t, s, 3, 0, nil, '3')
	testSeekAndReadByte(t, s, -2, 1, nil, '2')
	testReadAt(t, s, 7, nil, "789...")
	testSeekAndReadByte(t, s, 2, 1, nil, '5')
	testSeekAndReadByte(t, s, -2, 2, nil, '8')
	testUnreadByte(t, s, nil)
	testSeekAndReadByte(t, s, 0, 1, nil, '8')
	// test resize
	testTruncate(t, s, 20, stream.ErrNotGrowable)
	testSetSize(t, s, 20, stream.ErrNotGrowable)
	testPosition(t, s, 9)
	pos := 6
	s.Seek(int64(pos), 0)
	testTruncate(t, s, pos+1, nil)
	testPosition(t, s, pos)
	testTruncate(t, s, 0, nil)
	testPosition(t, s, 0)
	testReadAt(t, s, 5, io.EOF, "......")
	testSetSize(t, s, 10, nil)
	testPosition(t, s, 0)
	testReadAt(t, s, 5, nil, "56789.")
}
		0x31, 0xFA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 27+9  sfixed64:fixed64
		0x50, 0xFC, 0xFD, 0xFF, 0xFF, 0x0F, // 36+6  uint32:varint
		0x58, 0xFA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, // 42+11 uint64:varint
		0x65, 0xFC, 0xFE, 0xFF, 0xFF, // 53+5  fixed32:fixed32
		0x69, 0xFA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 58+9  fixed64:fixed64
		0xA5, 0x01, 0x39, 0x8E, 0xE3, 0x3D, // 67+6  float:fixed32
		0xA9, 0x01, 0x1C, 0xC7, 0x71, 0x1C, 0xC7, 0x71, 0xBC, 0x3F, // 73+10 double:fixed64
		0xF0, 0x01, 0x01, // 83+3  bool:varint
		0xFA, 0x01, 0x03, 0x31, 0x32, 0x33, // 86+6  string
		0x80, 0x02, 0x1E, // 92+3  enum:varint
		0xC2, 0x02, 0x06, 0x08, 0xFF, 0x03, 0x10, 0xFF, 0x11, // 95+9  message
		0xC2, 0x02, 0x06, 0x08, 0xFF, 0x11, 0x10, 0xFF, 0x03, //104+9  message
	}
)
var (
	rd   = stream.NewStreamFrom(pb_data)
	wr   = stream.NewStream(0)
	dm   = stream.NewStream(0)
	comp = new(pbDoor)
)

type pbPos struct {
	X, Y int32
}
type pbDoor struct {
	I32, S32, D32 int32
	I64, S64, D64 int64
	U32, X32      uint32
	U64, X64      uint64
	F32           float32
	F64           float64