Пример #1
0
func (e *encoderDecoder) marshal(tStruct thrift.TStruct) ([]byte, error) {
	tMemoryBuffer := thrift.NewTMemoryBuffer()
	tProtocol := e.tProtocolFactory.GetProtocol(tMemoryBuffer)
	if err := tStruct.Write(tProtocol); err != nil {
		return nil, err
	}
	return tMemoryBuffer.Bytes(), nil
}
Пример #2
0
func (e *encoderDecoder) unmarshal(data []byte, tStruct thrift.TStruct) error {
	// TODO(pedge): size is not set within TMemoryBuffer, but from the implementation it does not
	// look like it matters, however this relies on an implementation detail
	tMemoryBuffer := &thrift.TMemoryBuffer{
		Buffer: bytes.NewBuffer(data),
	}
	tProtocol := e.tProtocolFactory.GetProtocol(tMemoryBuffer)
	return tStruct.Read(tProtocol)
}
Пример #3
0
func DeserializeThriftMessage(buf *bytes.Buffer, ts thrift.TStruct) (string, thrift.TMessageType, int32, error) {
	transport := thrift.NewStreamTransportR(buf)
	protocol := thrift.NewTBinaryProtocol(transport, false, false)
	name, typeId, seqId, err := protocol.ReadMessageBegin()
	if err != nil {
		return "", 0, 0, err
	}

	err = ts.Read(protocol)
	if err != nil {
		return "", 0, 0, err
	}

	return name, typeId, seqId, nil
}