Documentation ¶
Overview ¶
package byteparse provides a binary parser and utilities.
Index ¶
- func Tag(tag []byte) parser.Parser[byte, []byte]
- func UInt16(byteorder binary.ByteOrder) parser.Parser[byte, uint16]
- func UInt32(byteorder binary.ByteOrder) parser.Parser[byte, uint32]
- func UInt64(byteorder binary.ByteOrder) parser.Parser[byte, uint64]
- func UInt8() parser.Parser[byte, uint8]
- type CompleteInput
- type UnexpectedPrefixError
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Tag ¶ added in v0.2.1
Tag initializes a parser that checks the input starts with the tag prefix.
Example ¶
package main import ( "fmt" "github.com/Drumato/peachcomb/pkg/byteparse" ) func main() { t := []byte{0x7f, 0x45, 0x4c, 0x46} b := byteparse.NewCompleteInput([]byte{0x7f, 0x45, 0x4c, 0x46, 0x02}) _, o, err := byteparse.Tag(t)(b) fmt.Printf("%d\n", len(o)) fmt.Printf("%x %x %x %x\n", o[0], o[1], o[2], o[3]) fmt.Println(err) }
Output: 4 7f 45 4c 46 <nil>
func UInt16 ¶
Uint16 initializes a parser that parse 16-bit unsigned integer. user can determine the behavior of this parser by giving byteorder what you want to use.
Example ¶
package main import ( "encoding/binary" "fmt" "github.com/Drumato/peachcomb/pkg/byteparse" ) func main() { b := byteparse.NewCompleteInput([]byte{0x01, 0x02, 0x03}) _, o, err := byteparse.UInt16(binary.BigEndian)(b) fmt.Printf("0x%x\n", o) fmt.Println(err) }
Output: 0x102 <nil>
func UInt32 ¶ added in v0.1.5
Uint32 initializes a parser that parse 32-bit unsigned integer. user can determine the behavior of this parser by giving byteorder what you want to use.
Example ¶
package main import ( "encoding/binary" "fmt" "github.com/Drumato/peachcomb/pkg/byteparse" ) func main() { b := byteparse.NewCompleteInput([]byte{0x01, 0x02, 0x03, 0x04}) _, o, err := byteparse.UInt32(binary.BigEndian)(b) fmt.Printf("0x%x\n", o) fmt.Println(err) }
Output: 0x1020304 <nil>
func UInt64 ¶ added in v0.1.5
Uint64 initializes a parser that parse 64-bit unsigned integer. user can determine the behavior of this parser by giving byteorder what you want to use.
func UInt8 ¶
Uint8 initializes a parser that parse 8-bit unsigned integer.
Example ¶
package main import ( "fmt" "github.com/Drumato/peachcomb/pkg/byteparse" ) func main() { b := byteparse.NewCompleteInput([]byte{0x01, 0x02, 0x03}) _, o, err := byteparse.UInt8()(b) fmt.Println(o) fmt.Println(err) }
Output: 1 <nil>
Types ¶
type CompleteInput ¶ added in v0.3.0
type CompleteInput struct {
// contains filtered or unexported fields
}
CompleteInput holds the whole bytes.
func NewCompleteInput ¶ added in v0.3.0
func NewCompleteInput(bytes []byte) *CompleteInput
NewCompleteInput initialiizes a CompleteInput.
type UnexpectedPrefixError ¶ added in v0.2.1
type UnexpectedPrefixError struct {
// contains filtered or unexported fields
}
UnexpectedPrefixError notifies the prefix of the given input is unexpected.
func (*UnexpectedPrefixError) Error ¶ added in v0.2.1
func (e *UnexpectedPrefixError) Error() string
Error implements error interface.