本文整理汇总了Golang中protocol.Response.Encode方法的典型用法代码示例。如果您正苦于以下问题:Golang Response.Encode方法的具体用法?Golang Response.Encode怎么用?Golang Response.Encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类protocol.Response
的用法示例。
在下文中一共展示了Response.Encode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: WriteResponse
func (self *ProtobufRequestHandler) WriteResponse(conn net.Conn, response *protocol.Response) error {
data, err := response.Encode()
if err != nil {
log.Error("error encoding response: %s", err)
return err
}
if len(data) >= MAX_RESPONSE_SIZE {
pointCount := len(response.Series.Points)
firstHalfPoints := response.Series.Points[:pointCount]
secondHalfPoints := response.Series.Points[pointCount:]
response.Series.Points = firstHalfPoints
err := self.WriteResponse(conn, response)
if err != nil {
return err
}
response.Series.Points = secondHalfPoints
return self.WriteResponse(conn, response)
}
buff := bytes.NewBuffer(make([]byte, 0, len(data)+8))
binary.Write(buff, binary.LittleEndian, uint32(len(data)))
_, err = conn.Write(append(buff.Bytes(), data...))
if err != nil {
log.Error("error writing response: %s", err)
return err
}
return nil
}
示例2: WriteResponse
func (self *ProtobufRequestHandler) WriteResponse(conn net.Conn, response *protocol.Response) error {
data, err := response.Encode()
if err != nil {
log.Error("error encoding response: %s", err)
return err
}
err = binary.Write(conn, binary.LittleEndian, uint32(len(data)))
if err != nil {
log.Error("error writing response length: %s", err)
return err
}
_, err = conn.Write(data)
return err
}