Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Deserialize ¶
Deserialize `data` according to the schema of `s`, and store the value into it. `s` must be a pointer type variable that points to the original schema of `data`.
Example ¶
package main
import (
"log"
"github.com/near/borsh-go"
)
type A struct {
B int32
}
func main() {
a := A{B: 123}
data, _ := borsh.Serialize(a)
b := &A{}
err := borsh.Deserialize(b, data)
if err != nil {
log.Fatal(err)
}
}
Output:
func Serialize ¶
Serialize `s` into bytes according to Borsh's specification(https://borsh.io/).
The type mapping can be found at https://github.com/near/borsh-go.
Example ¶
package main
import (
"log"
"github.com/near/borsh-go"
)
type A struct {
B int32
}
func main() {
a := A{B: 123}
data, err := borsh.Serialize(a)
if err != nil {
log.Fatal(err)
}
log.Print(data)
}
Output:
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
func NewDecoder ¶
Example ¶
package main
import (
"bytes"
"log"
"github.com/near/borsh-go"
)
type A struct {
B int32
}
func main() {
a := A{B: 123}
data, _ := borsh.Serialize(a)
b := &A{}
d := borsh.NewDecoder(bytes.NewReader(data))
if err := d.Decode(b); err != nil {
log.Fatal(err)
}
}
Output:
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
func NewEncoder ¶
Example ¶
package main
import (
"log"
"strings"
"github.com/near/borsh-go"
)
type A struct {
B int32
}
func main() {
a := A{B: 123}
b := strings.Builder{}
e := borsh.NewEncoder(&b)
if err := e.Encode(a); err != nil {
log.Fatal(err)
}
}
Output:
Click to show internal directories.
Click to hide internal directories.