當前位置: 首頁>>代碼示例>>Golang>>正文


Golang thrift.TProtocol類代碼示例

本文整理匯總了Golang中github.com/chentao/thrift/lib/go/thrift.TProtocol的典型用法代碼示例。如果您正苦於以下問題:Golang TProtocol類的具體用法?Golang TProtocol怎麽用?Golang TProtocol使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了TProtocol類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Read

func (p *ThriftFlumeEvent) Read(iprot thrift.TProtocol) error {
	if _, err := iprot.ReadStructBegin(); err != nil {
		return fmt.Errorf("%T read error: %s", p, err)
	}
	for {
		_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
		if err != nil {
			return fmt.Errorf("%T field %d read error: %s", p, fieldId, err)
		}
		if fieldTypeId == thrift.STOP {
			break
		}
		switch fieldId {
		case 1:
			if err := p.ReadField1(iprot); err != nil {
				return err
			}
		case 2:
			if err := p.ReadField2(iprot); err != nil {
				return err
			}
		default:
			if err := iprot.Skip(fieldTypeId); err != nil {
				return err
			}
		}
		if err := iprot.ReadFieldEnd(); err != nil {
			return err
		}
	}
	if err := iprot.ReadStructEnd(); err != nil {
		return fmt.Errorf("%T read struct end error: %s", p, err)
	}
	return nil
}
開發者ID:chentao,項目名稱:heka-flume,代碼行數:35,代碼來源:ttypes.go

示例2: ReadField2

func (p *ThriftFlumeEvent) ReadField2(iprot thrift.TProtocol) error {
	if v, err := iprot.ReadBinary(); err != nil {
		return fmt.Errorf("error reading field 2: %s", err)
	} else {
		p.Body = v
	}
	return nil
}
開發者ID:chentao,項目名稱:heka-flume,代碼行數:8,代碼來源:ttypes.go

示例3: ReadField0

func (p *AppendBatchResult) ReadField0(iprot thrift.TProtocol) error {
	if v, err := iprot.ReadI32(); err != nil {
		return fmt.Errorf("error reading field 0: %s", err)
	} else {
		temp := Status(v)
		p.Success = &temp
	}
	return nil
}
開發者ID:chentao,項目名稱:heka-flume,代碼行數:9,代碼來源:thriftsourceprotocol.go

示例4: writeField1

func (p *AppendArgs) writeField1(oprot thrift.TProtocol) (err error) {
	if err := oprot.WriteFieldBegin("event", thrift.STRUCT, 1); err != nil {
		return fmt.Errorf("%T write field begin error 1:event: %s", p, err)
	}
	if err := p.Event.Write(oprot); err != nil {
		return fmt.Errorf("%T error writing struct: %s", p.Event, err)
	}
	if err := oprot.WriteFieldEnd(); err != nil {
		return fmt.Errorf("%T write field end error 1:event: %s", p, err)
	}
	return err
}
開發者ID:chentao,項目名稱:heka-flume,代碼行數:12,代碼來源:thriftsourceprotocol.go

示例5: ReadField1

func (p *ThriftFlumeEvent) ReadField1(iprot thrift.TProtocol) error {
	_, _, size, err := iprot.ReadMapBegin()
	if err != nil {
		return fmt.Errorf("error reading map begin: %s", err)
	}
	tMap := make(map[string]string, size)
	p.Headers = tMap
	for i := 0; i < size; i++ {
		var _key0 string
		if v, err := iprot.ReadString(); err != nil {
			return fmt.Errorf("error reading field 0: %s", err)
		} else {
			_key0 = v
		}
		var _val1 string
		if v, err := iprot.ReadString(); err != nil {
			return fmt.Errorf("error reading field 0: %s", err)
		} else {
			_val1 = v
		}
		p.Headers[_key0] = _val1
	}
	if err := iprot.ReadMapEnd(); err != nil {
		return fmt.Errorf("error reading map end: %s", err)
	}
	return nil
}
開發者ID:chentao,項目名稱:heka-flume,代碼行數:27,代碼來源:ttypes.go

示例6: ReadField1

func (p *AppendBatchArgs) ReadField1(iprot thrift.TProtocol) error {
	_, size, err := iprot.ReadListBegin()
	if err != nil {
		return fmt.Errorf("error reading list begin: %s", err)
	}
	tSlice := make([]*ThriftFlumeEvent, 0, size)
	p.Events = tSlice
	for i := 0; i < size; i++ {
		_elem8 := &ThriftFlumeEvent{}
		if err := _elem8.Read(iprot); err != nil {
			return fmt.Errorf("%T error reading struct: %s", _elem8, err)
		}
		p.Events = append(p.Events, _elem8)
	}
	if err := iprot.ReadListEnd(); err != nil {
		return fmt.Errorf("error reading list end: %s", err)
	}
	return nil
}
開發者ID:chentao,項目名稱:heka-flume,代碼行數:19,代碼來源:thriftsourceprotocol.go

示例7: writeField2

func (p *ThriftFlumeEvent) writeField2(oprot thrift.TProtocol) (err error) {
	if err := oprot.WriteFieldBegin("body", thrift.STRING, 2); err != nil {
		return fmt.Errorf("%T write field begin error 2:body: %s", p, err)
	}
	if err := oprot.WriteBinary(p.Body); err != nil {
		return fmt.Errorf("%T.body (2) field write error: %s", p, err)
	}
	if err := oprot.WriteFieldEnd(); err != nil {
		return fmt.Errorf("%T write field end error 2:body: %s", p, err)
	}
	return err
}
開發者ID:chentao,項目名稱:heka-flume,代碼行數:12,代碼來源:ttypes.go

示例8: writeField0

func (p *AppendBatchResult) writeField0(oprot thrift.TProtocol) (err error) {
	if p.IsSetSuccess() {
		if err := oprot.WriteFieldBegin("success", thrift.I32, 0); err != nil {
			return fmt.Errorf("%T write field begin error 0:success: %s", p, err)
		}
		if err := oprot.WriteI32(int32(*p.Success)); err != nil {
			return fmt.Errorf("%T.success (0) field write error: %s", p, err)
		}
		if err := oprot.WriteFieldEnd(); err != nil {
			return fmt.Errorf("%T write field end error 0:success: %s", p, err)
		}
	}
	return err
}
開發者ID:chentao,項目名稱:heka-flume,代碼行數:14,代碼來源:thriftsourceprotocol.go

示例9: Write

func (p *AppendBatchResult) Write(oprot thrift.TProtocol) error {
	if err := oprot.WriteStructBegin("appendBatch_result"); err != nil {
		return fmt.Errorf("%T write struct begin error: %s", p, err)
	}
	if err := p.writeField0(oprot); err != nil {
		return err
	}
	if err := oprot.WriteFieldStop(); err != nil {
		return fmt.Errorf("write field stop error: %s", err)
	}
	if err := oprot.WriteStructEnd(); err != nil {
		return fmt.Errorf("write struct stop error: %s", err)
	}
	return nil
}
開發者ID:chentao,項目名稱:heka-flume,代碼行數:15,代碼來源:thriftsourceprotocol.go

示例10: Write

func (p *ThriftFlumeEvent) Write(oprot thrift.TProtocol) error {
	if err := oprot.WriteStructBegin("ThriftFlumeEvent"); err != nil {
		return fmt.Errorf("%T write struct begin error: %s", p, err)
	}
	if err := p.writeField1(oprot); err != nil {
		return err
	}
	if err := p.writeField2(oprot); err != nil {
		return err
	}
	if err := oprot.WriteFieldStop(); err != nil {
		return fmt.Errorf("write field stop error: %s", err)
	}
	if err := oprot.WriteStructEnd(); err != nil {
		return fmt.Errorf("write struct stop error: %s", err)
	}
	return nil
}
開發者ID:chentao,項目名稱:heka-flume,代碼行數:18,代碼來源:ttypes.go

示例11: writeField1

func (p *ThriftFlumeEvent) writeField1(oprot thrift.TProtocol) (err error) {
	if err := oprot.WriteFieldBegin("headers", thrift.MAP, 1); err != nil {
		return fmt.Errorf("%T write field begin error 1:headers: %s", p, err)
	}
	if err := oprot.WriteMapBegin(thrift.STRING, thrift.STRING, len(p.Headers)); err != nil {
		return fmt.Errorf("error writing map begin: %s", err)
	}
	for k, v := range p.Headers {
		if err := oprot.WriteString(string(k)); err != nil {
			return fmt.Errorf("%T. (0) field write error: %s", p, err)
		}
		if err := oprot.WriteString(string(v)); err != nil {
			return fmt.Errorf("%T. (0) field write error: %s", p, err)
		}
	}
	if err := oprot.WriteMapEnd(); err != nil {
		return fmt.Errorf("error writing map end: %s", err)
	}
	if err := oprot.WriteFieldEnd(); err != nil {
		return fmt.Errorf("%T write field end error 1:headers: %s", p, err)
	}
	return err
}
開發者ID:chentao,項目名稱:heka-flume,代碼行數:23,代碼來源:ttypes.go

示例12: Process

func (p *thriftSourceProtocolProcessorAppendBatch) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
	args := AppendBatchArgs{}
	if err = args.Read(iprot); err != nil {
		iprot.ReadMessageEnd()
		x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error())
		oprot.WriteMessageBegin("appendBatch", thrift.EXCEPTION, seqId)
		x.Write(oprot)
		oprot.WriteMessageEnd()
		oprot.Flush()
		return false, err
	}

	iprot.ReadMessageEnd()
	result := AppendBatchResult{}
	var retval Status
	var err2 error
	if retval, err2 = p.handler.AppendBatch(args.Events); err2 != nil {
		x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing appendBatch: "+err2.Error())
		oprot.WriteMessageBegin("appendBatch", thrift.EXCEPTION, seqId)
		x.Write(oprot)
		oprot.WriteMessageEnd()
		oprot.Flush()
		return true, err2
	} else {
		result.Success = &retval
	}
	if err2 = oprot.WriteMessageBegin("appendBatch", thrift.REPLY, seqId); err2 != nil {
		err = err2
	}
	if err2 = result.Write(oprot); err == nil && err2 != nil {
		err = err2
	}
	if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil {
		err = err2
	}
	if err2 = oprot.Flush(); err == nil && err2 != nil {
		err = err2
	}
	if err != nil {
		return
	}
	return true, err
}
開發者ID:chentao,項目名稱:heka-flume,代碼行數:43,代碼來源:thriftsourceprotocol.go


注:本文中的github.com/chentao/thrift/lib/go/thrift.TProtocol類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。