Documentation
¶
Overview ¶
Package pack provides methods to deal with self describing files of proto data.
The file format consists of a magic marker, followed by a Header. After that is a repeated sequence of uvarint length, tag and matching encoded message pair. Some section tags will also be followed by a string. The tag 0 is special, and marks a type entry, the body will be a descriptor.DescriptorProto.
Index ¶
- Constants
- Variables
- func Read(ctx context.Context, from io.Reader, events Events, forceDynamic bool) error
- type Dynamic
- type ErrUnknownType
- type ErrUnsupportedVersion
- type Events
- type Version
- type Writer
- func (w *Writer) BeginChildGroup(ctx context.Context, msg proto.Message, parentID uint64) (id uint64, err error)
- func (w *Writer) BeginGroup(ctx context.Context, msg proto.Message) (id uint64, err error)
- func (w *Writer) ChildObject(ctx context.Context, msg proto.Message, parentID uint64) error
- func (w *Writer) EndGroup(ctx context.Context, id uint64) error
- func (w *Writer) Object(ctx context.Context, msg proto.Message) error
Constants ¶
const ( // ErrIncorrectMagic is the error returned when the file header is not matched. ErrIncorrectMagic = fault.Const("Incorrect pack magic header") )
Variables ¶
var ( // MinMajorVersion is the current minimum supported major version of pack files. MinMajorVersion = 2 // MaxMajorVersion is the current maximum supported major version of pack files. MaxMajorVersion = 2 )
Functions ¶
Types ¶
type Dynamic ¶ added in v0.6.0
type Dynamic struct { Desc *descriptor.DescriptorProto Fields map[string]interface{} // contains filtered or unexported fields }
Dynamic is a dynamic proto message.
func (Dynamic) Format ¶ added in v0.6.0
Format implements fmt.Formatter to print the full value chain.
func (Dynamic) ProtoMessage ¶ added in v0.6.0
func (Dynamic) ProtoMessage()
type ErrUnknownType ¶
type ErrUnknownType struct{ TypeName string }
ErrUnknownType is the error returned by Reader.Unmarshal() when it encounters an unknown proto type.
func (ErrUnknownType) Error ¶
func (e ErrUnknownType) Error() string
type ErrUnsupportedVersion ¶ added in v0.6.0
type ErrUnsupportedVersion struct{ Version Version }
ErrUnsupportedVersion is the error returned when the header version is one this package cannot handle.
func (ErrUnsupportedVersion) Error ¶ added in v0.6.0
func (e ErrUnsupportedVersion) Error() string
type Events ¶ added in v0.6.0
type Events interface { // BeginGroup is called to start a new root group with the given identifier. BeginGroup(ctx context.Context, msg proto.Message, id uint64) error // BeginChildGroup is called to start a new group with the given identifier // as a child of the group with the parent identifier. BeginChildGroup(ctx context.Context, msg proto.Message, id, parentID uint64) error // EndGroup finalizes the group with the given identifier. It is illegal to // attempt to add children to the group after this is called. // EndGroup should be closed immediately after the last child has been added // to the group. EndGroup(ctx context.Context, id uint64) error // Object is called to declare an object outside of any group. Object(ctx context.Context, msg proto.Message) error // ChildObject is called to declare an object in the group with the given // identifier. ChildObject(ctx context.Context, msg proto.Message, parentID uint64) error }
Events describes the events used to construct groups and objects that are stored in a proto-pack stream.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer is the type for a pack file writer. They should only be constructed by NewWriter.
func NewWriter ¶
NewWriter constructs and returns a new Writer that writes to the supplied output stream. This method will write the packfile magic and header to the underlying stream.
func (*Writer) BeginChildGroup ¶ added in v0.6.0
func (w *Writer) BeginChildGroup(ctx context.Context, msg proto.Message, parentID uint64) (id uint64, err error)
BeginChildGroup is called to start a new group as a child of the group with the parent identifier.
func (*Writer) BeginGroup ¶ added in v0.6.0
BeginGroup is called to start a new root group.
func (*Writer) ChildObject ¶ added in v0.6.0
ChildObject is called to declare an object in the group with the given identifier.