diff options
| author | Shulhan <ms@kilabit.info> | 2024-09-25 23:57:01 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2024-09-30 23:04:56 +0700 |
| commit | 04ab5cfb262c8dbdadf2090bde99506ff2eac5a9 (patch) | |
| tree | f4ae4c1357266f81c9c51d9c7c3d10d8abc260d4 /lib/bytes/bytes_example_test.go | |
| parent | accefcac3be38899a6f05d8eefec8ac8f11a8ddd (diff) | |
| download | pakakeh.go-04ab5cfb262c8dbdadf2090bde99506ff2eac5a9.tar.xz | |
lib/bytes: add function AppendInt64 and AppendUint64
The AppendInt64 append an int64 value into slice of byte.
The AppendUint64 append an uint64 value into slice of byte.
Diffstat (limited to 'lib/bytes/bytes_example_test.go')
| -rw-r--r-- | lib/bytes/bytes_example_test.go | 60 |
1 files changed, 57 insertions, 3 deletions
diff --git a/lib/bytes/bytes_example_test.go b/lib/bytes/bytes_example_test.go index d1efbafe..0c2fbf49 100644 --- a/lib/bytes/bytes_example_test.go +++ b/lib/bytes/bytes_example_test.go @@ -1,6 +1,6 @@ -// Copyright 2018, Shulhan <ms@kilabit.info>. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. +// SPDX-FileCopyrightText: 2018 M. Shulhan <ms@kilabit.info> +// +// SPDX-License-Identifier: BSD-3-Clause package bytes_test @@ -38,6 +38,33 @@ func ExampleAppendInt32() { // 2147483647 => 0x7fffffff => []byte{0x7f, 0xff, 0xff, 0xff} } +func ExampleAppendInt64() { + var listInt64 = []int64{ + math.MaxInt64, + 1000, + math.MinInt64, + } + + var ( + v int64 + out []byte + ) + for _, v = range listInt64 { + out = libbytes.AppendInt64(nil, v) + fmt.Printf("%d\n=> %#x\n=> %#v\n", v, v, out) + } + // Output: + // 9223372036854775807 + // => 0x7fffffffffffffff + // => []byte{0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} + // 1000 + // => 0x3e8 + // => []byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0xe8} + // -9223372036854775808 + // => -0x8000000000000000 + // => []byte{0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0} +} + func ExampleAppendUint16() { inputs := []uint16{0, 0xab, 0xabc, math.MaxInt16, math.MaxUint16} for _, v := range inputs { @@ -78,6 +105,33 @@ func ExampleAppendUint32() { // 1 => 0x1 => []byte{0x0, 0x0, 0x0, 0x1} } +func ExampleAppendUint64() { + var listUint64 = []uint64{ + math.MaxUint64, + math.MaxInt64, + 1000, + } + + var ( + v uint64 + out []byte + ) + for _, v = range listUint64 { + out = libbytes.AppendUint64(nil, v) + fmt.Printf("%d\n=> %#x\n=> %#v\n", v, v, out) + } + // Output: + // 18446744073709551615 + // => 0xffffffffffffffff + // => []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} + // 9223372036854775807 + // => 0x7fffffffffffffff + // => []byte{0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} + // 1000 + // => 0x3e8 + // => []byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0xe8} +} + func ExampleConcat() { fmt.Printf("%s\n", libbytes.Concat()) fmt.Printf("%s\n", libbytes.Concat([]byte{})) |
