aboutsummaryrefslogtreecommitdiff
path: root/lib/bytes
AgeCommit message (Collapse)Author
11 daysall: apply go fixShulhan
2026-01-15all: convert license and copyright to use SPDX identifiersShulhan
With help of spdxconv tool [1], we able to bulk update all files license and copyright format to comply with SPDX formats. [1] https://kilabit.info/project/spdxconv/
2025-04-18lib/bytes: add method Peek to ParserShulhan
The Peek method take a look on n bytes inside the buffer without using delimiters. The returned bytes may empty or have length less than n.
2025-04-18lib/bytes: complete the SkipLine example until the endShulhan
This is to see the return value when no token can be parsed and to make the test coverage become 100%.
2025-01-23all: use for-range with numericShulhan
Go 1.22 now support for-range on numeric value.
2025-01-23all: replace [lib/bytes.WriteXxx] with standard libraryShulhan
The "encoding/binary.BigEndian" in standard library provides method PutXxx that do the same thing.
2025-01-23all: replace "lib/bytes.ReadXxx" with standard libraryShulhan
Package "encoding/binary" from standard library support reading integer from bytes using BigEndian, LittleEndian variables.
2025-01-23all: replace "lib/bytes.AppendXxx" with standard libraryShulhan
Since Go 1.19, package "encoding/binary.BigEndian" support appending byte order.
2025-01-22lib/bytes: replace Copy and Concat with standard libraryShulhan
Since Go 1.20, the standard bytes package have the Copy function. Since Go 1.22, the standard slices package have the Concat function.
2024-12-28lib/bytes: split the hexdump related functions to separate packageShulhan
Package hexdump implements reading and writing bytes from and into hexadecimal number. It support parsing output from hexdump(1) tool.
2024-09-30lib/bytes: add function AppendInt64 and AppendUint64Shulhan
The AppendInt64 append an int64 value into slice of byte. The AppendUint64 append an uint64 value into slice of byte.
2024-03-26lib/bytes: add parameter networkByteOrder to ParseHexDumpShulhan
If networkByteOrder is true, the ParseHexDump read each hex string in network byte order or as order defined in text. While at it, fix reading and parsing single byte hex.
2024-03-25lib/bytes: add test for Parser Read and ReadNoSpaceShulhan
The test initialize Parser with seven delimiters, '\t', '=', '\n', ' ', '"', '(', and ')' and then Read token from multi lines contents.
2024-03-05all: comply with linter recommendations #2Shulhan
HTTP request now implicitly create request with context. Any false positive related to not closing HTTP response body has been annotated with "nolint:bodyclose". In the example code, use consistent "// Output:" comment format, by prefixing with single space. Any comment on code now also prefixing with single space. An error returned without variables now use [errors.New] instead of [fmt.Errorf]. Any error returned using [fmt.Errorf] now wrapped using "%w" instead of "%s". Also, replace error checking using [errors.Is] or [errors.As], instead of using equal/not-equal operator. Any statement like "x = x OP y" now replaced with "x OP= y". Also, swap statement is simplified using "x, y = y, x". Any switch statement with single case now replaced with if-condition. Any call to defer on function or program that call [os.Exit], now replaced by calling the deferred function directly. Any if-else condition now replaced with switch statement, if possible.
2024-03-02all: move the repository to "git.sr.ht/~shulhan/pakakeh.go"Shulhan
There are several reasons that why we move from github.com. First, related to the name of package. We accidentally name the package with "share" a common word in English that does not reflect the content of repository. By moving to other repository, we can rename it to better and unique name, in this "pakakeh.go". Pakakeh is Minang word for tools, and ".go" suffix indicate that the repository related to Go programming language. Second, supporting open source. The new repository is hosted under sourcehut.org, the founder is known to support open source, and all their services are licensed under AGPL, unlike GitHub that are closed sources. Third, regarding GitHub CoPilot. The GitHub Terms of Service [1], allow any public content that are hosted there granted them to parse the content. On one side, GitHub helps and flourish the open source, but on another side have an issues regarding scraping the copyleft license [2]. [1]: https://docs.github.com/en/site-policy/github-terms/github-terms-of-service#4-license-grant-to-us [2]: https://githubcopilotinvestigation.com
2023-06-04lib/bytes: use %q to print characters in example codeShulhan
The %q will print the character itself if its printable or an hexadecimal representation.
2023-06-04lib/bytes: add function RemoveSpacesShulhan
Unlike TrimSpaces, which only remove spaces on beginning and end, RemoveSpaces remove all spaces including in between characters.
2023-04-13lib/bytes: fix linter warnings from reviveShulhan
2023-04-13lib/bytes: move unit Test for Read and SkipLine to ExampleShulhan
Using an example not only test the code but also provide example snippet when opened in the godoc.
2023-04-13lib/bytes: change the package name in Example to have _test suffixShulhan
Package name in test Example should be different with the actual package. This is to minimize leaking un-exported functions or methods.
2023-04-09lib/bytes: add method ReadLine to ParserShulhan
The ReadLine method read until it found new line ('\n') or end of content, ignoring all delimiters. The returned line will not contain '\n'.
2023-04-09lib/bytes: return the number of skipped chars on Skip(Horizontal)SpacesShulhan
2023-04-09lib/bytes: add method Remaining to ParserShulhan
The Remaining method return the copy of un-parsed content.
2023-04-08lib/bytes: add various methods to ParserShulhan
The AddDelimiters method add another delimiters to the current parser. The ReadNoSpace method read the next token by ignoring the leading spaces, even if its one of the delimiter. The returned token will have no trailing spaces. The RemoveDelimiters method remove delimiters delims from current delimiters. The Reset method set all internal state to new content and delimiters. The SetDelimiters method replace the current delimiters with delims. The SkipHorizontalSpaces method skip space (" "), tab ("\t"), carriage return ("\r"), and form feed ("\f") characters; and return the first non-space character or 0 if it reach end-of-content. The SkipSpaces method skip all spaces character (' ', '\f', '\n', '\r', '\t') and return the first non-space character or 0 if it reach end-of-content. The Stop method stop the parser, return the remaining unparsed content and its last position, and then call Reset to reset the internal state back to zero. The UnreadN method unread N characters and return the character its pointed to. If N greater than current position index, it will reset the read pointer index back to zero.
2023-04-05lib/bytes: implement function ParseHexDumpShulhan
The ParseHexDump parse the default output of [hexdump](1) utility from parameter in back into stream of byte. An example of default output of hexdump is 0000000 7865 5f70 6964 2f72 0000 0000 0000 0000 0000010 0000 0000 0000 0000 0000 0000 0000 0000 * 0000060 0000 0000 3030 3030 3537 0035 3030 3130 The first column is the address and the rest of the column is the data. Each data column is 16-bit words in big-endian order, so in the above example, the first byte would be 65, second byte is 78 and so on. The asterisk "*" means that the address from 0000020 to 0000050 is equal to the previous line, 0000010. [hexdump]: https://man.archlinux.org/man/hexdump.1
2023-04-05lib/bytes: implement tokenize ParserShulhan
The Parser type parse stream of byte using one or more delimiters as separator between token.
2023-04-05lib/bytes: add function TrimNullShulhan
The TrimNull function remove 0 value ("\0" or NULL in C) at leading and trailing of input.
2023-04-04lib/bytes: changes the DumpPrettyTable output formatShulhan
The change is to accommodate large bytes data, more than 0xFFFF. The hex address in the first column is increased to 8 digits, the characters compacted without space in between.
2023-04-03lib/bytes: copy TokenFind to internal/bytes#TokenFindShulhan
This is to prevent import cycle later when we use lib/test in bytes.
2023-03-22lib/bytes: add function DumpPrettyTableShulhan
The DumpPrettyTable write each byte in slice data as hexadecimal, ASCII character, and integer with 8 columns width.
2023-03-22lib/bytes: add function SplitEachShulhan
The SplitEach funciton split the slice of byte into n number of bytes. If n is less or equal than zero, it will return the data as chunks.
2022-05-09all: reformat all codes using gofmt 1.19 (the Go tip)Shulhan
2021-10-17lib/bytes: refactoring and cleaning up the bytes packageShulhan
The bytes package, and many other packages in this module, is written when I still learning and using the Go language for master thesis. Some of the code, like function signature, does not follow the Go idiom, at least not how the Go source code looks like. A breaking changes, * WriteUint16 and WriteUint32 accept slice only without pointer. There is no need to pass slice as pointer to function if we want to modify the content, as long as the backing storage is not changed. Bug fixes, * PrintHex: fix print layout on the last line * ReadHexByte: fix possible index out of range * SkipAfterToken return -1 and false if no token found, as promised in the comment, instead of the length of text. We move all unit test to example so we have test and example in the documentation at the same time. This changes make all test coverage 100%.
2021-10-14lib/bytes: refactoring AppendXxx functionsShulhan
Previously, we pass pointer to slice on AppendInt16, AppendInt32, AppendUint16, and AppendUint32 functions. This model of function signature is not a Go idiom. It is written when I am still new to Go.
2021-07-12lib/bytes: print the ASCII character on the right side on PrintHexShulhan
Previously, PrintHex only print the hex value of all bytes with specified length. This changes also print any printables ASCII characters (char 33 through 126) in the right side column to view readable contents.
2021-03-14all: refactoring the test.Assert and test.AssertBench signatureShulhan
Previously, the test.Assert and test.AssertBench functions has the boolean parameter to print the stack trace of test in case its not equal. Since this parameter is not mandatory and its usually always set to "true", we remove them from function signature to simplify the call to Assert and AssertBench.
2020-06-06all: use default linter optionsShulhan
2020-06-04bytes: add function MergeSpacesShulhan
The function MergeSpaces will convert sequences of white space into single space ' '.
2020-02-13bytes: move function JSONEscape and JSONUnescape to package jsonShulhan
2019-10-03bytes: fix empty test case on IsTokenAtShulhan
2019-09-27bytes: add function to get indexes of word in stringShulhan
Unlike Indexes, the word parameter must be separated by space or placed at beginning or end of string.
2019-09-25bytes: add function to take snippets from string by indexesShulhan
2019-09-24bytes: add function get all indexes of token in stringShulhan
2019-06-14ascii: new library for working with ASCII charactersShulhan
This library previously part of bytes package. To make it bytes package consistent (only working with slice of byte), we move all ASCII related constants, variables, and functions into new package.
2019-06-14all: fix nolint formatShulhan
The valid syntax to suppress linter warnings is "//nolint:<name>" with no space between comment and "nolint" and between ":". Also, we move the placement of nolint directive to the top of statements for multiple nolint in the same scope. While at it, fix and supress some linter warnings.
2019-03-05bytes: change the Copy return type to non pointerShulhan
Non pointer slice is less confusing than with pointer.
2019-03-04bytes: add function to concat slice of byte or string into []byteShulhan
2019-03-02all: suppress "dupl" linter warnings on test filesShulhan
2019-03-01all: fix warnings from linterShulhan
Most of the warnings caused by update to linter which cause global variables declared with grouping "( ... )" and that has been suppressed, are become false-positive again.
2019-02-21memfs: add method to dump files as Go generated sourceShulhan
If you familiar with go-bindata [1], this method is similar with that. [1] github.com/shuLhan/go-bindata