diff options
| author | Chris Lu <chris.lu@gmail.com> | 2013-02-10 03:09:26 -0800 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2013-02-10 03:09:26 -0800 |
| commit | cb4e8ec16b5c204718f1efdc1731f1bdd5698ff3 (patch) | |
| tree | 47f27040c3d80e6849932bf2acf54b68c930f72b /src/weed/util/bytes.go | |
| parent | d3b267bac27018b7f70dfec7c258d0556fff4c14 (diff) | |
| download | seaweedfs-cb4e8ec16b5c204718f1efdc1731f1bdd5698ff3.tar.xz seaweedfs-cb4e8ec16b5c204718f1efdc1731f1bdd5698ff3.zip | |
re-organize code directory structure
Diffstat (limited to 'src/weed/util/bytes.go')
| -rw-r--r-- | src/weed/util/bytes.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/weed/util/bytes.go b/src/weed/util/bytes.go new file mode 100644 index 000000000..6cc3d7018 --- /dev/null +++ b/src/weed/util/bytes.go @@ -0,0 +1,33 @@ +package util + +func BytesToUint64(b []byte) (v uint64) { + length := uint(len(b)) + for i := uint(0); i < length-1; i++ { + v += uint64(b[i]) + v <<= 8 + } + v += uint64(b[length-1]) + return +} +func BytesToUint32(b []byte) (v uint32) { + length := uint(len(b)) + for i := uint(0); i < length-1; i++ { + v += uint32(b[i]) + v <<= 8 + } + v += uint32(b[length-1]) + return +} +func Uint64toBytes(b []byte, v uint64) { + for i := uint(0); i < 8; i++ { + b[7-i] = byte(v >> (i * 8)) + } +} +func Uint32toBytes(b []byte, v uint32) { + for i := uint(0); i < 4; i++ { + b[3-i] = byte(v >> (i * 8)) + } +} +func Uint8toBytes(b []byte, v uint8) { + b[0] = byte(v) +} |
