本文整理汇总了Golang中encoding/binary.Read函数的典型用法代码### 示例。如果您正苦于以下问题:Golang Read函数的具体用法?Golang Read怎么用?Golang Read使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。
在下文中一共展示了Read函数的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。
示例1: convertIPPDateToTime
// convertIPPDateToTime converts an RFC 2579 date to a time.Time object.
func convertIPPDateToTime(date *C.ipp_uchar_t) time.Time {
r := bytes.NewReader(C.GoBytes(unsafe.Pointer(date), 11))
var year uint16
var month, day, hour, min, sec, dsec uint8
binary.Read(r, binary.BigEndian, &year)
binary.Read(r, binary.BigEndian, &month)
binary.Read(r, binary.BigEndian, &day)
binary.Read(r, binary.BigEndian, &hour)
binary.Read(r, binary.BigEndian, &min)
binary.Read(r, binary.BigEndian, &sec)
binary.Read(r, binary.BigEndian, &dsec)
var utcDirection, utcHour, utcMin uint8
binary.Read(r, binary.BigEndian, &utcDirection)
binary.Read(r, binary.BigEndian, &utcHour)
binary.Read(r, binary.BigEndian, &utcMin)
var utcOffset time.Duration
utcOffset += time.Duration(utcHour) * time.Hour
utcOffset += time.Duration(utcMin) * time.Minute
var loc *time.Location
if utcDirection == '-' {
loc = time.FixedZone("", -int(utcOffset.Seconds()))
} else {
loc = time.FixedZone("", int(utcOffset.Seconds()))
}
nsec := int(dsec) * 100 * int(time.Millisecond)
return time.Date(int(year), time.Month(month), int(day), int(hour), int(min), int(sec), nsec, loc)
}
开发者ID:TechEdge01,项目名称:cups-connector,代码行数:32,代码来源:cups.go
示例2: ReadNewInvalidState
func ReadNewInvalidState(in io.Reader) *NewInvalidState {
var reason, gameMode byte
binary.Read(in, ByteOrder, &reason)
binary.Read(in, ByteOrder, &gameMode)
ptr := NewInvalidState{reason, gameMode}
return &ptr
}
开发者ID:mvm,项目名称:ChinoFarmer,代码行数:7,代码来源:net.go
示例3: ReadFrom
func (e *indexEntry) ReadFrom(r io.Reader) (n int64, err error) {
var deleted byte
if err = binary.Read(r, binary.BigEndian, &deleted); err != nil {
return 0, err
}
e.deleted = (deleted != 0)
var value_len uint32
if err = binary.Read(r, binary.BigEndian, &value_len); err != nil {
return 0, err
}
value := make([]byte, int(value_len))
for i := 0; i < int(value_len); i++ {
var b byte
if err = binary.Read(r, binary.BigEndian, &b); err != nil {
return 0, err
}
value[i] = b
}
e.value = string(value)
var id int64
if err = binary.Read(r, binary.BigEndian, &id); err != nil {
return 0, err
}
e.id = id
return int64(binary.Size(deleted) + binary.Size(value) + binary.Size(id)), nil
}
开发者ID:screscent,项目名称:epos,代码行数:30,代码来源:index.go
示例4: ReadTimestampedEntryInto
// ReadTimestampedEntryInto parses the byte-stream representation of a
// TimestampedEntry from |r| and populates the struct |t| with the data. See
// RFC section 3.4 for details on the format.
// Returns a non-nil error if there was a problem.
func ReadTimestampedEntryInto(r io.Reader, t *TimestampedEntry) error {
var err error
if err = binary.Read(r, binary.BigEndian, &t.Timestamp); err != nil {
return err
}
if err = binary.Read(r, binary.BigEndian, &t.EntryType); err != nil {
return err
}
switch t.EntryType {
case X509LogEntryType:
if t.X509Entry, err = readVarBytes(r, CertificateLengthBytes); err != nil {
return err
}
case PrecertLogEntryType:
if err := binary.Read(r, binary.BigEndian, &t.PrecertEntry.IssuerKeyHash); err != nil {
return err
}
if t.PrecertEntry.TBSCertificate, err = readVarBytes(r, PreCertificateLengthBytes); err != nil {
return err
}
case XJSONLogEntryType:
if t.JSONData, err = readVarBytes(r, JSONLengthBytes); err != nil {
return err
}
default:
return fmt.Errorf("unknown EntryType: %d", t.EntryType)
}
t.Extensions, err = readVarBytes(r, ExtensionsLengthBytes)
return nil
}
开发者ID:jfrazelle,项目名称:cfssl,代码行数:34,代码来源:serialization.go
示例5: readStats
func readStats(r io.Reader, typ string) (*ReferenceStats, error) {
var (
vOff uint64
stats ReferenceStats
err error
)
err = binary.Read(r, binary.LittleEndian, &vOff)
if err != nil {
return nil, fmt.Errorf("%s: failed to read index stats chunk begin virtual offset: %v", typ, err)
}
stats.Chunk.Begin = makeOffset(vOff)
err = binary.Read(r, binary.LittleEndian, &vOff)
if err != nil {
return nil, fmt.Errorf("%s: failed to read index stats chunk end virtual offset: %v", typ, err)
}
stats.Chunk.End = makeOffset(vOff)
err = binary.Read(r, binary.LittleEndian, &stats.Mapped)
if err != nil {
return nil, fmt.Errorf("%s: failed to read index stats mapped count: %v", typ, err)
}
err = binary.Read(r, binary.LittleEndian, &stats.Unmapped)
if err != nil {
return nil, fmt.Errorf("%s: failed to read index stats unmapped count: %v", typ, err)
}
return &stats, nil
}
开发者ID:pombredanne,项目名称:hts,代码行数:26,代码来源:index_read.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng