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


Golang ByteOrder.PutUint64方法代碼示例

本文整理匯總了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
}
開發者ID:untoldwind,項目名稱:gorrd,代碼行數:34,代碼來源:raw_data_file.go

示例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
}
開發者ID:decred,項目名稱:dcrd,代碼行數:10,代碼來源:common.go

示例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
}
開發者ID:Cisko-Rijken,項目名稱:go-expanse,代碼行數:9,代碼來源:trie_test.go

示例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()
	}
}
開發者ID:Cisko-Rijken,項目名稱:go-expanse,代碼行數:13,代碼來源:trie_test.go

示例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
}
開發者ID:rwcarlsen,項目名稱:gobitmsg,代碼行數:18,代碼來源:structures.go

示例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
}
開發者ID:ZhangTingkuo,項目名稱:FishChatServer,代碼行數:41,代碼來源:protocol.go

示例7: WriteUint64

func (b *Buffer) WriteUint64(u uint64, order binary.ByteOrder) error {
	i := b.Grows(8)
	order.PutUint64(b.Buf[i:], u)
	return nil
}
開發者ID:huangjiasingle,項目名稱:gohper,代碼行數:5,代碼來源:buffer.go

示例8: writeFloat

func writeFloat(buf []byte, byteOrder binary.ByteOrder, value float64) {
	u := math.Float64bits(value)
	byteOrder.PutUint64(buf, u)
}
開發者ID:dgraph-io,項目名稱:dgraph,代碼行數:4,代碼來源:binary.go


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