epp

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ProtocolIDIdle     uint8 = 0 // '000' Encapsulation Idle Packet (fill data)
	ProtocolIDLTP      uint8 = 1 // '001' Licklider Transmission Protocol (CCSDS 734.1)
	ProtocolIDIPE      uint8 = 2 // '010' Internet Protocol Extension
	ProtocolIDCFDP     uint8 = 3 // '011' CCSDS File Delivery Protocol (CCSDS 727.0)
	ProtocolIDBP       uint8 = 4 // '100' Bundle Protocol (CCSDS 734.2)
	ProtocolIDExtended uint8 = 6 // '110' protocol identified by the Protocol ID Extension field
	ProtocolIDMission  uint8 = 7 // '111' mission-specific, privately defined data
)

Encapsulation Protocol ID values per CCSDS 133.1-B-3 Section 4.1.2.3 and the SANA Encapsulation Protocol ID registry.

View Source
const (
	LoLNone   uint8 = 0 // '00' (no Packet Length field; 1-octet header (idle only)
	LoL1Octet uint8 = 1 // '01') 1-octet Packet Length; 2-octet header
	LoL2Octet uint8 = 2 // '10' (2-octet Packet Length; 4-octet header
	LoL4Octet uint8 = 3 // '11') 4-octet Packet Length; 8-octet header
)

Length of Length values per CCSDS 133.1-B-3 table 4-1. The value selects both the size of the Packet Length field and the total header size.

View Source
const (
	HeaderSize1 = 1 // LoL '00'
	HeaderSize2 = 2 // LoL '01'
	HeaderSize4 = 4 // LoL '10'
	HeaderSize8 = 8 // LoL '11'
)

Header sizes in octets, a pure function of the Length of Length field.

View Source
const (
	MaxPacketLength2 = 255        // 1-octet Packet Length field (2-octet header)
	MaxPacketLength4 = 65535      // 2-octet Packet Length field (4-octet header)
	MaxPacketLength8 = 4294967295 // 4-octet Packet Length field (8-octet header)
)

Maximum total packet lengths (header included) per header size.

View Source
const PVN = 7

PVN is the Packet Version Number for Encapsulation Packets ('111') per CCSDS 133.1-B-3 Section 4.1.2.2.

Variables

View Source
var (
	// ErrInvalidPVN indicates the Packet Version Number is not 7 ('111').
	ErrInvalidPVN = errors.New("invalid PVN: must be 7 ('111') for encapsulation packets")

	// ErrInvalidProtocolID indicates the Protocol ID is out of range.
	ErrInvalidProtocolID = errors.New("invalid protocol ID: must be in the range 0-7")

	// ErrInvalidLengthOfLength indicates the Length of Length field is not 0-3.
	ErrInvalidLengthOfLength = errors.New("invalid length of length: must be in the range 0-3")

	// ErrInvalidUserDefined indicates the User Defined Field does not fit in 4 bits.
	ErrInvalidUserDefined = errors.New("invalid user defined field: must be in the range 0-15")

	// ErrInvalidExtendedProtocolID indicates the Protocol ID Extension does not fit in 4 bits.
	ErrInvalidExtendedProtocolID = errors.New("invalid protocol ID extension: must be in the range 0-15")

	// ErrNonIdleOneOctetHeader indicates a 1-octet header (LoL '00') with a
	// non-idle Protocol ID, which CCSDS 133.1-B-3 4.1.2.4.4 forbids.
	ErrNonIdleOneOctetHeader = errors.New("length of length '00' requires protocol ID '000' (idle)")

	// ErrExtendedNeedsLongHeader indicates Protocol ID '110' with a header too
	// short to carry the Protocol ID Extension field.
	ErrExtendedNeedsLongHeader = errors.New("protocol ID '110' requires a 4- or 8-octet header")

	// ErrExtensionMustBeZero indicates a non-zero Protocol ID Extension while
	// the Protocol ID is not '110' (CCSDS 133.1-B-3 4.1.2.6.3).
	ErrExtensionMustBeZero = errors.New("protocol ID extension must be zero unless protocol ID is '110'")

	// ErrFieldNeedsLongerHeader indicates a header field is set that does not
	// exist in the selected header size (e.g. a CCSDS Defined value with a
	// 4-octet header).
	ErrFieldNeedsLongerHeader = errors.New("header field not present in the selected header size")

	// ErrIdleWithData indicates a 1-octet idle packet was given a data zone.
	ErrIdleWithData = errors.New("1-octet idle packet has no data zone")

	// ErrEmptyData indicates a non-idle packet has no data
	// (CCSDS 133.1-B-3 4.1.3.1.5).
	ErrEmptyData = errors.New("non-idle packet must contain data")

	// ErrDataTooShort indicates the provided data is too short for decoding.
	ErrDataTooShort = errors.New("provided data is too short to decode the packet")

	// ErrPacketLengthMismatch indicates the declared packet length does not match the actual size.
	ErrPacketLengthMismatch = errors.New("packet length field does not match actual packet size")

	// ErrPacketTooLarge indicates the packet exceeds the maximum size for its header format.
	ErrPacketTooLarge = errors.New("packet size exceeds the maximum for the selected header format")

	// ErrInvalidIdleLength indicates an idle fill packet was requested with an
	// unrepresentable total length.
	ErrInvalidIdleLength = errors.New("idle packet total length must be at least 1 octet")

	// ErrNilPacket indicates a nil packet was provided.
	ErrNilPacket = errors.New("packet must not be nil")
)

Functions

func HeaderSize

func HeaderSize(data []byte) int

HeaderSize returns the header size in bytes by inspecting the first byte of an encoded packet. Returns -1 if the data is too short or the first byte does not carry the encapsulation PVN ('111').

func PacketSizer

func PacketSizer(data []byte) int

PacketSizer returns the total length in bytes of the Encapsulation Packet starting at data[0], or -1 if the data is too short to determine length. This implements the sdl.PacketSizer signature for use with data link services.

Types

type EncapsulationPacket

type EncapsulationPacket struct {
	Header Header // Variable-length packet header
	Data   []byte // Encapsulated Data Field
}

EncapsulationPacket represents a complete Encapsulation Packet per CCSDS 133.1-B-3.

func Decode

func Decode(data []byte) (*EncapsulationPacket, error)

Decode parses a byte slice into an EncapsulationPacket. Trailing bytes beyond the declared packet length are ignored. The returned packet's Data field is a sub-slice of the input and shares the same backing array. Callers that reuse the input buffer should copy the Data field before modifying the buffer.

func NewIPEPacket

func NewIPEPacket(data []byte, options ...PacketOption) (*EncapsulationPacket, error)

NewIPEPacket creates an Internet Protocol Extension Encapsulation Packet.

func NewIdleFillPacket

func NewIdleFillPacket(totalLength int, fill byte) (*EncapsulationPacket, error)

NewIdleFillPacket creates an idle Encapsulation Packet of exactly totalLength octets, filling the data zone with the given fill byte. Use it to fill a fixed-length transfer frame data field. A totalLength of 1 yields the 1-octet idle packet.

func NewIdlePacket

func NewIdlePacket() (*EncapsulationPacket, error)

NewIdlePacket creates the 1-octet idle Encapsulation Packet (0xE0).

func NewLTPPacket

func NewLTPPacket(data []byte, options ...PacketOption) (*EncapsulationPacket, error)

NewLTPPacket creates an LTP Encapsulation Packet.

func NewMissionPacket

func NewMissionPacket(data []byte, options ...PacketOption) (*EncapsulationPacket, error)

NewMissionPacket creates a mission-specific ('111') Encapsulation Packet carrying privately defined data.

func NewPacket

func NewPacket(protocolID uint8, data []byte, options ...PacketOption) (*EncapsulationPacket, error)

NewPacket creates a new EncapsulationPacket with the given Protocol ID and data. The smallest header that fits the data is selected, unless an option forces a larger one. Protocol ID 0 with no data yields the 1-octet idle packet; Protocol ID 0 with data yields a multi-octet idle fill packet.

func (*EncapsulationPacket) Encode

func (ep *EncapsulationPacket) Encode() ([]byte, error)

Encode converts the EncapsulationPacket into a byte slice for transmission.

func (*EncapsulationPacket) Humanize

func (ep *EncapsulationPacket) Humanize() string

Humanize generates a human-readable representation of the EncapsulationPacket.

func (*EncapsulationPacket) IsIdle

func (ep *EncapsulationPacket) IsIdle() bool

IsIdle reports whether the packet is an idle packet (Protocol ID = 0).

func (*EncapsulationPacket) Validate

func (ep *EncapsulationPacket) Validate() error

Validate checks the integrity and correctness of the EncapsulationPacket.

type Header struct {
	PVN                uint8  // Packet Version Number (3 bits, must be 7)
	ProtocolID         uint8  // Encapsulation Protocol ID (3 bits, 0-7)
	LengthOfLength     uint8  // Length of Length (2 bits, 0-3)
	UserDefined        uint8  // User Defined Field (4 bits, 4- and 8-octet headers)
	ExtendedProtocolID uint8  // Protocol ID Extension (4 bits, 4- and 8-octet headers)
	CCSDSDefined       uint16 // CCSDS Defined Field (16 bits, 8-octet header only)
	PacketLength       uint32 // Total packet length in octets, header included
}

Header represents the variable-length header of an Encapsulation Packet.

func (*Header) Decode

func (h *Header) Decode(data []byte) error

Decode deserializes bytes into a Header. At least 1 byte must be provided; additional bytes are read as needed based on the Length of Length field.

func (*Header) Encode

func (h *Header) Encode() ([]byte, error)

Encode serializes the Header into bytes.

func (*Header) Humanize

func (h *Header) Humanize() string

Humanize generates a human-readable representation of the Header.

func (*Header) Size

func (h *Header) Size() int

Size returns the header size in octets, determined solely by the Length of Length field: '00'->1, '01'->2, '10'->4, '11'->8.

func (*Header) Validate

func (h *Header) Validate() error

Validate checks that all fields conform to CCSDS 133.1-B-3.

type PacketOption

type PacketOption func(*EncapsulationPacket) error

PacketOption defines a function type for configuring EncapsulationPacket options.

func WithCCSDSDefined

func WithCCSDSDefined(value uint16) PacketOption

WithCCSDSDefined sets the 2-octet CCSDS Defined Field, present only in the 8-octet header. This forces the 8-octet header. The field is reserved by CCSDS and is by convention 'all zeros' (4.1.2.7.2).

func WithExtendedProtocolID

func WithExtendedProtocolID(extPID uint8) PacketOption

WithExtendedProtocolID sets the 4-bit Protocol ID Extension field and the Protocol ID to '110' (ProtocolIDExtended). This raises the header size to at least 4 octets, since only 4- and 8-octet headers carry the field.

func WithLongLength

func WithLongLength() PacketOption

WithLongLength forces at least a 4-octet header (2-octet Packet Length field). NewPacket otherwise picks the smallest header that fits the data.

func WithUserDefined

func WithUserDefined(value uint8) PacketOption

WithUserDefined sets the 4-bit User Defined Field, present in 4- and 8-octet headers. This raises the header size to at least 4 octets.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service provides packet send/receive operations over a shared transport for Encapsulation Packets per CCSDS 133.1-B-3.

func NewService

func NewService(rw io.ReadWriter, cfg ServiceConfig) *Service

NewService creates a new EPP service over the given transport.

func (*Service) ReceiveBytes

func (s *Service) ReceiveBytes() (protocolID uint8, data []byte, err error)

ReceiveBytes reads an encapsulation packet from the transport and returns the Protocol ID and data zone, stripping away the packet structure.

func (*Service) ReceivePacket

func (s *Service) ReceivePacket() (*EncapsulationPacket, error)

ReceivePacket reads and decodes a complete encapsulation packet from the transport.

func (*Service) SendBytes

func (s *Service) SendBytes(protocolID uint8, data []byte, opts ...PacketOption) error

SendBytes wraps the given data in an encapsulation packet and writes it to the transport. The caller provides raw bytes and protocol ID; EPP handles packet construction.

func (*Service) SendPacket

func (s *Service) SendPacket(packet *EncapsulationPacket) error

SendPacket writes a pre-built encapsulation packet to the transport.

type ServiceConfig

type ServiceConfig struct {
	// MaxPacketLength is the maximum total packet size in octets.
	// It defaults to MaxPacketLength8 (4,294,967,295), the largest packet
	// the protocol can represent, so that spec-valid packets are never
	// rejected unless the mission configures a lower limit.
	MaxPacketLength int
}

ServiceConfig holds configuration for a Service.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL