Documentation
¶
Overview ¶
Package leb128 implements LEB128 codec.
The encode part is a fork of https://golang.org/src/cmd/internal/dwarf/dwarf.go
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendSleb128 ¶
AppendSleb128 appends v to b using signed LEB128 encoding.
Example ¶
package main
import (
"fmt"
"ekyu.moe/leb128"
)
func main() {
fmt.Printf("Encoded: %x\n", leb128.AppendSleb128(nil, -624485))
}
Output: Encoded: 9bf159
func AppendUleb128 ¶
AppendUleb128 appends v to b using unsigned LEB128 encoding.
Example ¶
package main
import (
"fmt"
"ekyu.moe/leb128"
)
func main() {
fmt.Printf("Encoded: %x\n", leb128.AppendUleb128(nil, 624485))
}
Output: Encoded: e58e26
func DecodeSleb128 ¶
DecodeSleb128 decodes b to s with signed LEB128 encoding and returns the number of bytes read. On error (bad encoded b), n will be 0 and therefore s must not be trusted.
Example ¶
package main
import (
"fmt"
"ekyu.moe/leb128"
)
func main() {
s, n := leb128.DecodeSleb128([]byte{0x9b, 0xf1, 0x59, 'd', 'e', 'f'})
fmt.Printf("Decoded: %d\nRead: %d bytes", s, n)
}
Output: Decoded: -624485 Read: 3 bytes
func DecodeUleb128 ¶
DecodeUleb128 decodes b to u with unsigned LEB128 encoding and returns the number of bytes read. On error (bad encoded b), n will be 0 and therefore u must not be trusted.
Example ¶
package main
import (
"fmt"
"ekyu.moe/leb128"
)
func main() {
u, n := leb128.DecodeUleb128([]byte{0xe5, 0x8e, 0x26, 'a', 'b', 'c'})
fmt.Printf("Decoded: %d\nRead: %d bytes", u, n)
}
Output: Decoded: 624485 Read: 3 bytes
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.