numeric

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package numeric provides parsers for recognizing numeric bytes

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Int16BE

func Int16BE() parser.Parser[parser.Reader, int16]

Int16BE returns a big endian 2 byte signed integer. io.EOF is returned if the input contains too few bytes

Example (EndOfFile)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{})
	numericParser := numeric.Int16BE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: '%v', Remainder: %v", match, err, remainder)

}
Output:

Match: 0, Error: 'EOF', Remainder: []
Example (Match)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{0x00, 0x01, 3})
	numericParser := numeric.Int16BE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: %v, Remainder: %v", match, err, remainder)

}
Output:

Match: 1, Error: <nil>, Remainder: [3]

func Int16LE

func Int16LE() parser.Parser[parser.Reader, int16]

Int16LE returns a little endian 2 byte signed integer. io.EOF is returned if the input contains too few bytes

Example (EndOfFile)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{})
	numericParser := numeric.Int16LE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: '%v', Remainder: %v", match, err, remainder)

}
Output:

Match: 0, Error: 'EOF', Remainder: []
Example (Match)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{0x01, 0x00, 3})
	numericParser := numeric.Int16LE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: %v, Remainder: %v", match, err, remainder)

}
Output:

Match: 1, Error: <nil>, Remainder: [3]

func Int32BE

func Int32BE() parser.Parser[parser.Reader, int32]

Int32BE returns a big endian 4 byte signed integer. io.EOF is returned if the input contains too few bytes

Example (EndOfFile)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{})
	numericParser := numeric.Int32BE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: '%v', Remainder: %v", match, err, remainder)

}
Output:

Match: 0, Error: 'EOF', Remainder: []
Example (Match)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{0x00, 0x00, 0x00, 0x01, 3})
	numericParser := numeric.Int32BE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: %v, Remainder: %v", match, err, remainder)

}
Output:

Match: 1, Error: <nil>, Remainder: [3]

func Int32LE

func Int32LE() parser.Parser[parser.Reader, int32]

Int32LE returns a little endian 4 byte signed integer. io.EOF is returned if the input contains too few bytes

Example (EndOfFile)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{})
	numericParser := numeric.Int32LE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: '%v', Remainder: %v", match, err, remainder)

}
Output:

Match: 0, Error: 'EOF', Remainder: []
Example (Match)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{0x01, 0x00, 0x00, 0x00, 3})
	numericParser := numeric.Int32LE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: %v, Remainder: %v", match, err, remainder)

}
Output:

Match: 1, Error: <nil>, Remainder: [3]

func Int64BE

func Int64BE() parser.Parser[parser.Reader, int64]

Int64BE returns a big endian 8 byte signed integer. io.EOF is returned if the input contains too few bytes

Example (EndOfFile)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{})
	numericParser := numeric.Int64BE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: '%v', Remainder: %v", match, err, remainder)

}
Output:

Match: 0, Error: 'EOF', Remainder: []
Example (Match)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 3})
	numericParser := numeric.Int64BE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: %v, Remainder: %v", match, err, remainder)

}
Output:

Match: 1, Error: <nil>, Remainder: [3]

func Int64LE

func Int64LE() parser.Parser[parser.Reader, int64]

Int64LE returns a little endian 8 byte signed integer. io.EOF is returned if the input contains too few bytes

Example (EndOfFile)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{})
	numericParser := numeric.Int64LE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: '%v', Remainder: %v", match, err, remainder)

}
Output:

Match: 0, Error: 'EOF', Remainder: []
Example (Match)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 3})
	numericParser := numeric.Int64LE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: %v, Remainder: %v", match, err, remainder)

}
Output:

Match: 1, Error: <nil>, Remainder: [3]

func Int8

func Int8() parser.Parser[parser.Reader, int8]

Int8 returns a 1 byte signed integer. io.EOF is returned if the input contains too few bytes

Example (EndOfFile)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{})
	numericParser := numeric.Int8()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: '%v', Remainder: %v", match, err, remainder)

}
Output:

Match: 0, Error: 'EOF', Remainder: []
Example (Match)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{1, 2, 3})
	numericParser := numeric.Int8()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: %v, Remainder: %v", match, err, remainder)

}
Output:

Match: 1, Error: <nil>, Remainder: [2 3]

func UInt16BE

func UInt16BE() parser.Parser[parser.Reader, uint16]

UInt16BE returns a big endian 2 byte unsigned integer. io.EOF is returned if the input contains too few bytes

Example (EndOfFile)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{})
	numericParser := numeric.UInt16BE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: '%v', Remainder: %v", match, err, remainder)

}
Output:

Match: 0, Error: 'EOF', Remainder: []
Example (Match)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{0x00, 0x01, 3})
	numericParser := numeric.UInt16BE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: %v, Remainder: %v", match, err, remainder)

}
Output:

Match: 1, Error: <nil>, Remainder: [3]

func UInt16LE

func UInt16LE() parser.Parser[parser.Reader, uint16]

UInt16LE returns a little endian 2 byte unsigned integer. io.EOF is returned if the input contains too few bytes

Example (EndOfFile)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{})
	numericParser := numeric.UInt16LE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: '%v', Remainder: %v", match, err, remainder)

}
Output:

Match: 0, Error: 'EOF', Remainder: []
Example (Match)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{0x01, 0x00, 3})
	numericParser := numeric.UInt16LE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: %v, Remainder: %v", match, err, remainder)

}
Output:

Match: 1, Error: <nil>, Remainder: [3]

func UInt32BE

func UInt32BE() parser.Parser[parser.Reader, uint32]

UInt32BE returns a big endian 4 byte unsigned integer. io.EOF is returned if the input contains too few bytes

Example (EndOfFile)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{})
	numericParser := numeric.UInt32BE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: '%v', Remainder: %v", match, err, remainder)

}
Output:

Match: 0, Error: 'EOF', Remainder: []
Example (Match)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{0x00, 0x00, 0x00, 0x01, 3})
	numericParser := numeric.UInt32BE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: %v, Remainder: %v", match, err, remainder)

}
Output:

Match: 1, Error: <nil>, Remainder: [3]

func UInt32LE

func UInt32LE() parser.Parser[parser.Reader, uint32]

UInt32LE returns a little endian 4 byte unsigned integer. io.EOF is returned if the input contains too few bytes

Example (EndOfFile)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{})
	numericParser := numeric.UInt32LE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: '%v', Remainder: %v", match, err, remainder)

}
Output:

Match: 0, Error: 'EOF', Remainder: []
Example (Match)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{0x01, 0x00, 0x00, 0x00, 3})
	numericParser := numeric.UInt32LE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: %v, Remainder: %v", match, err, remainder)

}
Output:

Match: 1, Error: <nil>, Remainder: [3]

func UInt64BE

func UInt64BE() parser.Parser[parser.Reader, uint64]

UInt64BE returns a big endian 8 byte unsigned integer. io.EOF is returned if the input contains too few bytes

Example (EndOfFile)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{})
	numericParser := numeric.UInt64BE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: '%v', Remainder: %v", match, err, remainder)

}
Output:

Match: 0, Error: 'EOF', Remainder: []
Example (Match)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 3})
	numericParser := numeric.UInt64BE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: %v, Remainder: %v", match, err, remainder)

}
Output:

Match: 1, Error: <nil>, Remainder: [3]

func UInt64LE

func UInt64LE() parser.Parser[parser.Reader, uint64]

UInt64LE returns a little endian 8 byte unsigned integer. io.EOF is returned if the input contains too few bytes

Example (EndOfFile)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{})
	numericParser := numeric.UInt64LE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: '%v', Remainder: %v", match, err, remainder)

}
Output:

Match: 0, Error: 'EOF', Remainder: []
Example (Match)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 3})
	numericParser := numeric.UInt64LE()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: %v, Remainder: %v", match, err, remainder)

}
Output:

Match: 1, Error: <nil>, Remainder: [3]

func UInt8

func UInt8() parser.Parser[parser.Reader, uint8]

UInt8 returns a 1 byte unsigned integer. io.EOF is returned if the input contains too few bytes

Example (EndOfFile)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{})
	numericParser := numeric.UInt8()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: '%v', Remainder: %v", match, err, remainder)

}
Output:

Match: 0, Error: 'EOF', Remainder: []
Example (Match)
package main

import (
	"bytes"
	"fmt"
	"github.com/roblovelock/gobble/pkg/parser/numeric"
	"io"
)

func main() {
	input := bytes.NewReader([]byte{1, 2, 3})
	numericParser := numeric.UInt8()

	match, err := numericParser(input)
	remainder, _ := io.ReadAll(input)
	fmt.Printf("Match: %d, Error: %v, Remainder: %v", match, err, remainder)

}
Output:

Match: 1, Error: <nil>, Remainder: [2 3]

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL