Documentation ¶
Overview ¶
Package proto contains mostly auto-generated code for parsing/packing SCION capnp messages, as well as some helper functions to working with capnp in Go simpler.
The helper functions are all contained in cereal.go. They provide a simple interface to read/write any capnp messages that have a Go representation, relying on https://godoc.org/zombiezen.com/go/capnproto2/pogs to do the heavy lifting.
One thing to note is that these helper functions generally only operate on complete capnp messages. If you, for example, want to create an IFID proto, that needs to be nested inside a SCION control message. For example:
// Create new ifid instance ifid1 := &ifid.IFID{OrigIfID: uint64(ifID)} // Wrap it in a SCION control message. cpld1, _ := ctrl.NewPld(ifid1) // Pack the ctrl message to bytes. b, _ := PackRoot(cpld1) // Parse new ctrl message from bytes. cpld2, _ := ParseFromRaw(b) // Access the contents (unnamed union). cont, _ := cpld2.Contents() // Interface-assertion to IFID type. ifid2 := cont.(*ifid.IFID)
Index ¶
- func PackRoot(c Cerealizable) (common.RawBytes, error)
- func ParseFromRaw(c Cerealizable, pType ProtoIdType, b common.RawBytes) error
- func ParseFromReader(c Cerealizable, pType ProtoIdType, r io.Reader) error
- func ParseStruct(c Cerealizable, pType ProtoIdType, s capnp.Struct) error
- func ReadRootFromRaw(b common.RawBytes) (capnp.Struct, error)
- func ReadRootFromReader(r io.Reader) (_ capnp.Struct, err error)
- func WriteRoot(c Cerealizable, b common.RawBytes) (int, error)
- type Cerealizable
- type ProtoIdType
- type SignS
- func (s *SignS) Copy() *SignS
- func (s *SignS) Pack() common.RawBytes
- func (s *SignS) ProtoId() ProtoIdType
- func (s *SignS) Sign(key, message common.RawBytes) (common.RawBytes, error)
- func (s *SignS) SignAndSet(key, message common.RawBytes) error
- func (s *SignS) String() string
- func (s *SignS) Time() time.Time
- func (s *SignS) Verify(key, message common.RawBytes) error
- type SignedBlobS
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PackRoot ¶
func PackRoot(c Cerealizable) (common.RawBytes, error)
PackRoot creates a complete capnp message for c, and returns it encoded as bytes.
func ParseFromRaw ¶
func ParseFromRaw(c Cerealizable, pType ProtoIdType, b common.RawBytes) error
ParseFromRaw is a utility function, which reads a capnp message from b and parses it into c. It is effectively a composition of ReadRootFromRaw and ParseStruct.
func ParseFromReader ¶
func ParseFromReader(c Cerealizable, pType ProtoIdType, r io.Reader) error
ParseFromReader is a utility function, which reads a capnp message from r and parses it into c. It is effectively a composition of ReadRootFromReader and ParseStruct.
func ParseStruct ¶
func ParseStruct(c Cerealizable, pType ProtoIdType, s capnp.Struct) error
ParseStruct parses a capnp struct into a Cerealizable instance.
func ReadRootFromRaw ¶
ReadRootFromRaw returns the root struct from a capnp message encoded in b.
func ReadRootFromReader ¶
ReadRootFromReader returns the root struct from a capnp message read from r.
Types ¶
type Cerealizable ¶
type Cerealizable interface { fmt.Stringer ProtoId() ProtoIdType }
Cerealizable represents a type which has a corresponding Cap'n Proto (capnp) representation, and supports pogs insertion/extraction.
type ProtoIdType ¶
type ProtoIdType uint64
ProtoIdType represents a capnp struct Id.
func (ProtoIdType) String ¶
func (p ProtoIdType) String() string
type SignS ¶
type SignS struct { Timestamp uint32 Type SignType // Src holds the required metadata to verify the signature. The format is "STRING: METADATA". // The prefix consists of "STRING: " and is required to match the regex "^\w+\: ". // There are no format restrictions on the metadata. Src common.RawBytes Signature common.RawBytes }
func (*SignS) ProtoId ¶
func (s *SignS) ProtoId() ProtoIdType
type SignedBlobS ¶
func (*SignedBlobS) Pack ¶
func (sbs *SignedBlobS) Pack() common.RawBytes
func (*SignedBlobS) ProtoId ¶
func (sbs *SignedBlobS) ProtoId() ProtoIdType
func (*SignedBlobS) String ¶
func (sbs *SignedBlobS) String() string