本文整理匯總了Golang中encoding/binary.ByteOrder.PutUint64方法的典型用法代碼示例。如果您正苦於以下問題:Golang ByteOrder.PutUint64方法的具體用法?Golang ByteOrder.PutUint64怎麽用?Golang ByteOrder.PutUint64使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類encoding/binary.ByteOrder
的用法示例。
在下文中一共展示了ByteOrder.PutUint64方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: OpenRawDataFile
// Open a CDataFile
func OpenRawDataFile(name string, readOnly bool, byteOrder binary.ByteOrder, byteAlignment uint64, valueSize int) (*RawDataFile, error) {
flag := os.O_RDWR
if readOnly {
flag = os.O_RDONLY
}
file, err := os.OpenFile(name, flag, 0644)
if err != nil {
return nil, err
}
var univalToBytes func([]byte, unival)
var bytesToUnival func([]byte) unival
switch valueSize {
case 8:
univalToBytes = func(dst []byte, src unival) {
byteOrder.PutUint64(dst, src.AsUnsignedLong())
}
bytesToUnival = func(src []byte) unival {
return unival(byteOrder.Uint64(src))
}
default:
return nil, errors.Errorf("Invalid value size %d", valueSize)
}
return &RawDataFile{
file: file,
// byteOrder: byteOrder,
byteAlignment: byteAlignment,
valueSize: valueSize,
univalToBytes: univalToBytes,
bytesToUnival: bytesToUnival,
}, nil
}
示例2: PutUint64
// PutUint64 serializes the provided uint64 using the given byte order into a
// buffer from the free list and writes the resulting eight bytes to the given
// writer.
func (l binaryFreeList) PutUint64(w io.Writer, byteOrder binary.ByteOrder, val uint64) error {
buf := l.Borrow()[:8]
byteOrder.PutUint64(buf, val)
_, err := w.Write(buf)
l.Return(buf)
return err
}
示例3: benchUpdate
func benchUpdate(b *testing.B, e binary.ByteOrder) *Trie {
trie := newEmpty()
k := make([]byte, 32)
for i := 0; i < b.N; i++ {
e.PutUint64(k, uint64(i))
trie.Update(k, k)
}
return trie
}
示例4: benchHash
func benchHash(b *testing.B, e binary.ByteOrder) {
trie := newEmpty()
k := make([]byte, 32)
for i := 0; i < benchElemCount; i++ {
e.PutUint64(k, uint64(i))
trie.Update(k, k)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
trie.Hash()
}
}
示例5: packUint
func packUint(order binary.ByteOrder, v interface{}) (data []byte) {
switch val := v.(type) {
case uint64:
data = make([]byte, 8)
order.PutUint64(data, val)
case uint32:
data = make([]byte, 4)
order.PutUint32(data, val)
case uint16:
data = make([]byte, 2)
order.PutUint16(data, val)
case uint8:
data = []byte{byte(val)}
default:
panic("unsupported type")
}
return data
}
示例6: newSimpleProtocol
func newSimpleProtocol(n int, byteOrder binary.ByteOrder) *simpleProtocol {
protocol := &simpleProtocol{
n: n,
bo: byteOrder,
}
switch n {
case 1:
protocol.encodeHead = func(buffer []byte) {
buffer[0] = byte(len(buffer) - n)
}
protocol.decodeHead = func(buffer []byte) int {
return int(buffer[0])
}
case 2:
protocol.encodeHead = func(buffer []byte) {
byteOrder.PutUint16(buffer, uint16(len(buffer)-n))
}
protocol.decodeHead = func(buffer []byte) int {
return int(byteOrder.Uint16(buffer))
}
case 4:
protocol.encodeHead = func(buffer []byte) {
byteOrder.PutUint32(buffer, uint32(len(buffer)-n))
}
protocol.decodeHead = func(buffer []byte) int {
return int(byteOrder.Uint32(buffer))
}
case 8:
protocol.encodeHead = func(buffer []byte) {
byteOrder.PutUint64(buffer, uint64(len(buffer)-n))
}
protocol.decodeHead = func(buffer []byte) int {
return int(byteOrder.Uint64(buffer))
}
default:
panic("unsupported packet head size")
}
return protocol
}
示例7: WriteUint64
func (b *Buffer) WriteUint64(u uint64, order binary.ByteOrder) error {
i := b.Grows(8)
order.PutUint64(b.Buf[i:], u)
return nil
}
示例8: writeFloat
func writeFloat(buf []byte, byteOrder binary.ByteOrder, value float64) {
u := math.Float64bits(value)
byteOrder.PutUint64(buf, u)
}