mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-10-31 13:50:01 +00:00 
			
		
		
		
	godep restore pushd $GOPATH/src/github.com/appc/spec git co master popd go get go4.org/errorutil rm -rf Godeps godep save ./... git add vendor git add -f $(git ls-files --other vendor/) git co -- Godeps/LICENSES Godeps/.license_file_state Godeps/OWNERS
		
			
				
	
	
		
			38 lines
		
	
	
		
			844 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			844 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package raftboltdb
 | |
| 
 | |
| import (
 | |
| 	"bytes"
 | |
| 	"encoding/binary"
 | |
| 
 | |
| 	"github.com/hashicorp/go-msgpack/codec"
 | |
| )
 | |
| 
 | |
| // Decode reverses the encode operation on a byte slice input
 | |
| func decodeMsgPack(buf []byte, out interface{}) error {
 | |
| 	r := bytes.NewBuffer(buf)
 | |
| 	hd := codec.MsgpackHandle{}
 | |
| 	dec := codec.NewDecoder(r, &hd)
 | |
| 	return dec.Decode(out)
 | |
| }
 | |
| 
 | |
| // Encode writes an encoded object to a new bytes buffer
 | |
| func encodeMsgPack(in interface{}) (*bytes.Buffer, error) {
 | |
| 	buf := bytes.NewBuffer(nil)
 | |
| 	hd := codec.MsgpackHandle{}
 | |
| 	enc := codec.NewEncoder(buf, &hd)
 | |
| 	err := enc.Encode(in)
 | |
| 	return buf, err
 | |
| }
 | |
| 
 | |
| // Converts bytes to an integer
 | |
| func bytesToUint64(b []byte) uint64 {
 | |
| 	return binary.BigEndian.Uint64(b)
 | |
| }
 | |
| 
 | |
| // Converts a uint to a byte slice
 | |
| func uint64ToBytes(u uint64) []byte {
 | |
| 	buf := make([]byte, 8)
 | |
| 	binary.BigEndian.PutUint64(buf, u)
 | |
| 	return buf
 | |
| }
 |