本文整理汇总了Golang中encoding/binary.Write函数的典型用法代码### 示例。如果您正苦于以下问题:Golang Write函数的具体用法?Golang Write怎么用?Golang Write使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。
在下文中一共展示了Write函数的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。
示例1: bigIntToNetIPv6
// bigIntToNetIPv6 is a helper function that correctly returns a net.IP with the
// correctly padded values.
func bigIntToNetIPv6(bi *big.Int) *net.IP {
x := make(net.IP, IPv6len)
ipv6Bytes := bi.Bytes()
// It's possibe for ipv6Bytes to be less than IPv6len bytes in size. If
// they are different sizes we to pad the size of response.
if len(ipv6Bytes) < IPv6len {
buf := new(bytes.Buffer)
buf.Grow(IPv6len)
for i := len(ipv6Bytes); i < IPv6len; i++ {
if err := binary.Write(buf, binary.BigEndian, byte(0)); err != nil {
panic(fmt.Sprintf("Unable to pad byte %d of input %v: %v", i, bi, err))
}
}
for _, b := range ipv6Bytes {
if err := binary.Write(buf, binary.BigEndian, b); err != nil {
panic(fmt.Sprintf("Unable to preserve endianness of input %v: %v", bi, err))
}
}
ipv6Bytes = buf.Bytes()
}
i := copy(x, ipv6Bytes)
if i != IPv6len {
panic("IPv6 wrong size")
}
return &x
}
开发者ID:luizbafilho,项目名称:fusis,代码行数:32,代码来源:ipv6addr.go
示例2: Write
func (obj GCAddEffectPacket) Write(buf io.Writer, code uint8) error {
binary.Write(buf, binary.LittleEndian, obj.ObjectID)
binary.Write(buf, binary.LittleEndian, obj.EffectID)
binary.Write(buf, binary.LittleEndian, obj.Duration)
return nil
}
开发者ID:sguzwf,项目名称:ouster,代码行数:7,代码来源:gc.go
示例3: WriteTo
func (e *indexEntry) WriteTo(w io.Writer) (n int64, err error) {
deleted := byte(0)
if e.deleted {
deleted = 1
}
if err = binary.Write(w, binary.BigEndian, deleted); err != nil {
return 0, err
}
value_len := uint32(len(e.value))
if err = binary.Write(w, binary.BigEndian, value_len); err != nil {
return 0, err
}
if err = binary.Write(w, binary.BigEndian, []byte(e.value)); err != nil {
return 0, err
}
if err = binary.Write(w, binary.BigEndian, e.id); err != nil {
return 0, err
}
return int64(binary.Size(deleted) + binary.Size([]byte(e.value)) + binary.Size(e.id)), nil
}
开发者ID:screscent,项目名称:epos,代码行数:25,代码来源:index.go
示例4: WriteEMessage
func (client *Client) WriteEMessage(emsg *EMessage) []byte {
buffer := new(bytes.Buffer)
binary.Write(buffer, binary.BigEndian, emsg.msgid)
binary.Write(buffer, binary.BigEndian, emsg.device_id)
SendMessage(buffer, emsg.msg)
return buffer.Bytes()
}
开发者ID:reasonz,项目名称:im_service,代码行数:7,代码来源:storage_server.go
示例5: serializeV1PrecertSCTSignatureInput
func serializeV1PrecertSCTSignatureInput(timestamp uint64, issuerKeyHash [issuerKeyHashLength]byte, tbs []byte, ext CTExtensions) ([]byte, error) {
if err := checkCertificateFormat(tbs); err != nil {
return nil, err
}
if err := checkExtensionsFormat(ext); err != nil {
return nil, err
}
var buf bytes.Buffer
if err := binary.Write(&buf, binary.BigEndian, V1); err != nil {
return nil, err
}
if err := binary.Write(&buf, binary.BigEndian, CertificateTimestampSignatureType); err != nil {
return nil, err
}
if err := binary.Write(&buf, binary.BigEndian, timestamp); err != nil {
return nil, err
}
if err := binary.Write(&buf, binary.BigEndian, PrecertLogEntryType); err != nil {
return nil, err
}
if _, err := buf.Write(issuerKeyHash[:]); err != nil {
return nil, err
}
if err := writeVarBytes(&buf, tbs, CertificateLengthBytes); err != nil {
return nil, err
}
if err := writeVarBytes(&buf, ext, ExtensionsLengthBytes); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
开发者ID:jfrazelle,项目名称:cfssl,代码行数:31,代码来源:serialization.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng