Documentation ¶
Overview ¶
Package bert implements the BERT serialization and RPC protocol. See http://bert-rpc.org/
Index ¶
- Constants
- Variables
- func Encode(val interface{}) ([]byte, error)
- func EncodeAndCompress(val interface{}, compress bool) ([]byte, error)
- func EncodeAndCompressUsingMinorVersion(val interface{}, compress bool, minorVersion int) ([]byte, error)
- func EncodeTo(w io.Writer, val interface{}) (err error)
- func EncodeToAndCompress(w io.Writer, val interface{}, compress bool) (err error)
- func EncodeToAndCompressUsingMinorVersion(w io.Writer, val interface{}, compress bool, minorVersion int) (err error)
- func EncodeToUsingMinorVersion(w io.Writer, val interface{}, minorVersion int) (err error)
- func EncodeUsingMinorVersion(val interface{}, minorVersion int) ([]byte, error)
- func Marshal(w io.Writer, val interface{}) error
- func MarshalAndCompress(w io.Writer, val interface{}, compress bool) error
- func MarshalAndCompressUsingMinorVersion(w io.Writer, val interface{}, compress bool, minorVersion int) error
- func MarshalResponse(w io.Writer, val interface{}) (err error)
- func MarshalResponseAndCompress(w io.Writer, val interface{}, compress bool) (err error)
- func MarshalResponseAndCompressUsingMinorVersion(w io.Writer, val interface{}, compress bool, minorVersion int) (err error)
- func MarshalResponseUsingMinorVersion(w io.Writer, val interface{}, minorVersion int) (err error)
- func MarshalUsingMinorVersion(w io.Writer, val interface{}, minorVersion int) error
- func Unmarshal(data []byte, val interface{}) (err error)
- func UnmarshalFrom(r io.Reader, val interface{}) (err error)
- type Atom
- type DistributionHeader
- type Export
- type Func
- type Map
- type NewFunc
- type NewReference
- type Pid
- type Port
- type Reference
- type Request
- type Term
- Bugs
Examples ¶
Constants ¶
const ( VersionTag = 131 DistributionHeaderTag = 68 CompressedTag = 80 SmallIntTag = 97 IntTag = 98 SmallBignumTag = 110 LargeBignumTag = 111 FloatTag = 99 NewFloatTag = 70 AtomCacheRefTag = 82 AtomTag = 100 SmallAtomTag = 115 AtomUtf8Tag = 118 SmallAtomUtf8Tag = 119 SmallTupleTag = 104 LargeTupleTag = 105 NilTag = 106 StringTag = 107 ListTag = 108 BinTag = 109 MapTag = 116 PidTag = 103 PortTag = 102 FunTag = 117 ReferenceTag = 101 NewReferenceTag = 114 NewFunTag = 112 ExportTag = 113 )
const ( BertAtom = Atom("bert") NilAtom = Atom("nil") TrueAtom = Atom("true") FalseAtom = Atom("false") )
const ( MinorVersion0 = 0 MinorVersion1 = 1 )
const ( // NewCacheEntry is used to determine if an entry is a new cache entry NewCacheEntry byte = 8 // SegmentIndex can be used to extract the segment index SegmentIndex byte = 7 // LongAtoms is used to determine if 2 byte atoms are used LongAtoms byte = 1 )
Variables ¶
Functions ¶
func EncodeAndCompress ¶
EncodeAndCompress encodes val and returns it or an error. If compress is true the body will be compressed
func EncodeAndCompressUsingMinorVersion ¶
func EncodeAndCompressUsingMinorVersion(val interface{}, compress bool, minorVersion int) ([]byte, error)
EncodeAndCompressUsingMinorVersion encodes val and returns it or an error. If compress is true the body will be compressed It will use the minor version for the encoding
func EncodeToAndCompress ¶
EncodeToAndCompress encodes val and writes it to w, returning any error. If compress is true the body will be compressed
func EncodeToAndCompressUsingMinorVersion ¶
func EncodeToAndCompressUsingMinorVersion(w io.Writer, val interface{}, compress bool, minorVersion int) (err error)
EncodeToAndCompress encodes val and writes it to w, returning any error. If compress is true the body will be compressed
func EncodeToUsingMinorVersion ¶
EncodeTo encodes val and writes it to w, returning any error.
func EncodeUsingMinorVersion ¶
Encode encodes val and returns it or an error.
func MarshalAndCompress ¶
MarshalAndCompress is an alias for EncodeTo. If compress is true the body will be compressed
func MarshalAndCompressUsingMinorVersion ¶
func MarshalAndCompressUsingMinorVersion(w io.Writer, val interface{}, compress bool, minorVersion int) error
MarshalAndCompress is an alias for EncodeTo. If compress is true the body will be compressed It will use the minor version for the encoding
func MarshalResponse ¶
MarshalResponse encodes val into a BURP Response struct and writes it to w, returning any error.
func MarshalResponseAndCompress ¶
MarshalResponseAndCompress encodes val into a BURP Response struct and writes it to w, returning any error. If compress is true the body will be compressed
func MarshalResponseAndCompressUsingMinorVersion ¶
func MarshalResponseAndCompressUsingMinorVersion(w io.Writer, val interface{}, compress bool, minorVersion int) (err error)
MarshalResponseAndCompress encodes val into a BURP Response struct and writes it to w, returning any error. If compress is true the body will be compressed It will use the minor version for the encoding
func MarshalResponseUsingMinorVersion ¶
MarshalResponse encodes val into a BURP Response struct and writes it to w, returning any error.
func MarshalUsingMinorVersion ¶
Marshal is an alias for EncodeTo.
func Unmarshal ¶
Unmarshal decodes a value from data, stores it in val, and returns any error encountered.
func UnmarshalFrom ¶
UnmarshalFrom decodes a value from r, stores it in val, and returns any error encountered.
Types ¶
type DistributionHeader ¶
type DistributionHeader struct {
// contains filtered or unexported fields
}
As of erts version 5.7.2 the old atom cache protocol was dropped and a new one was introduced. This atom cache protocol introduced the distribution header. Nodes with erts versions earlier than 5.7.2 can still communicate with new nodes, but no distribution header and no atom cache will be used.
The distribution header currently only contains an atom cache reference section, but could in the future contain more information. The distribution header precedes one or more Erlang terms on the external format. For more information see the documentation of the protocol between connected nodes in the distribution protocol documentation.
ATOM_CACHE_REF entries with corresponding AtomCacheReferenceIndex in terms encoded on the external format following a distribution header refers to the atom cache references made in the distribution header. The range is 0 <= AtomCacheReferenceIndex < 255, i.e., at most 255 different atom cache references from the following terms can be made.
type Export ¶
Export wraps the EXPORT_EXT tag type (113) This term is the encoding for external funs: fun M:F/A.
Module and Function are atoms (encoded using ATOM_EXT, SMALL_ATOM_EXT or ATOM_CACHE_REF).
Arity is an integer encoded using SMALL_INTEGER_EXT.
type Func ¶
Func wraps the FUN_EXT tag type (117)
Pid is a process identifier as in PID_EXT. It represents the process in which the fun was created.
Module is an encoded as an atom, using ATOM_EXT, SMALL_ATOM_EXT or ATOM_CACHE_REF. This is the module that the fun is implemented in.
Index is an integer encoded using SMALL_INTEGER_EXT or INTEGER_EXT. It is typically a small index into the module's fun table.
Uniq is an integer encoded using SMALL_INTEGER_EXT or INTEGER_EXT. Uniq is the hash value of the parse for the fun.
Free vars is NumFree number of terms, each one encoded according to its type.
type Map ¶
maptag is a specific type that allows us to override the print statement to always ensure that the keys are printed in order
type NewFunc ¶
type NewFunc struct { Arity uint8 Uniq []byte Index uint32 Module Atom OldIndex uint32 OldUnique uint32 Pid Pid FreeVars []Term }
NewFunc wraps the NEW_FUN_EXT tag type (112) This is the new encoding of internal funs: fun F/A and fun(Arg1,..) -> ... end.
Size is the total number of bytes, including the Size field.
Arity is the arity of the function implementing the fun.
Uniq is the 16 bytes MD5 of the significant parts of the Beam file.
Index is an index number. Each fun within a module has an unique index. Index is stored in big-endian byte order.
NumFree is the number of free variables.
Module is an encoded as an atom, using ATOM_EXT, SMALL_ATOM_EXT or ATOM_CACHE_REF. This is the module that the fun is implemented in.
OldIndex is an integer encoded using SMALL_INTEGER_EXT or INTEGER_EXT. It is typically a small index into the module's fun table.
OldUniq is an integer encoded using SMALL_INTEGER_EXT or INTEGER_EXT. Uniq is the hash value of the parse tree for the fun.
Pid is a process identifier as in PID_EXT. It represents the process in which the fun was created.
Free vars is NumFree number of terms, each one encoded according to its type.
type NewReference ¶
NewReference wraps the NEW_REFERENCE_EXT tag type (114)
Node and Creation are as in REFERENCE_EXT.
ID contains a sequence of big-endian unsigned integers (4 bytes each, so N' is a multiple of 4), but should be regarded as uninterpreted data.
N' = 4 * Len.
In the first word (four bytes) of ID, only 18 bits are significant, the rest should be 0.
In Creation, only 2 bits are significant, the rest should be 0.
NEW_REFERENCE_EXT was introduced with distribution version 4. In version 4, N' should be at most 12
type Pid ¶
Pid wraps the PID_EXT tag type (103)
Encode a process identifier object (obtained from spawn/3 or friends). The ID and Creation fields works just like in REFERENCE_EXT, while the Serial field is used to improve safety. In ID, only 15 bits are significant; the rest should be 0.
type Port ¶
Port wraps the PORT_EXT tag type (102)
Encode a port object (obtained form open_port/2). The ID is a node specific identifier for a local port. Port operations are not allowed across node boundaries. The Creation works just like in REFERENCE_EXT.
type Reference ¶
Reference wraps the REFERENCE_EXT tag type (101)
Encode a reference object (an object generated with make_ref/0).
The Node term is an encoded atom, i.e. ATOM_EXT, SMALL_ATOM_EXT or ATOM_CACHE_REF.
The ID field contains a big-endian unsigned integer, but should be regarded as uninterpreted data since this field is node specific. Creation is a byte containing a node serial number that makes it possible to separate old (crashed) nodes from a new one.
In ID, only 18 bits are significant; the rest should be 0. In Creation, only 2 bits are significant; the rest should be 0. See NEW_REFERENCE_EXT.
type Term ¶
type Term interface{}
func Decode ¶
Decode decodes a Term from data and returns it or an error.
Example ¶
i, err := Decode([]byte{131, 97, 42}) if err != nil { fmt.Println(err) } fmt.Printf("%#v\n", i) s, err := Decode([]byte{131, 107, 0, 3, 102, 111, 111}) if err != nil { fmt.Println(err) } fmt.Printf("%#v\n", s) a, err := Decode([]byte{131, 104, 1, 100, 0, 3, 102, 111, 111}) if err != nil { fmt.Println(err) } fmt.Printf("%#v\n", a)
Output: 42 "foo" []bert.Term{"foo"}
Notes ¶
Bugs ¶
Full BERT specification compliance is still in progress.