serialize

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package serialize provides frame serialization interfaces and implementations.

Package serialize provides binary envelope encoding using wire.FrameEnvelope (wire_frames.proto). ProtoEncoder/ProtoDecoder use standard protobuf wire format; ReadProtoEnvelope reads length-prefixed envelopes from a stream.

Package serialize provides binary frame protobuf encode/decode for frames.

Package serialize provides JSON (and optional protobuf) encoding/decoding for frames.

Package serialize implements binary frame wire encoding/decoding without depending on generated descriptor (avoids init issues when protoc is not available).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeByType

func DecodeByType(typ string, data []byte) (frames.Frame, error)

DecodeByType decodes the payload into the concrete frame type.

func Decoder

func Decoder(data []byte) (frames.Frame, error)

Decoder decodes JSON (envelope format) into a Frame using the type field.

func Encoder

func Encoder(f frames.Frame) ([]byte, error)

Encoder encodes a Frame to JSON with a type discriminator. Wire format: no trailing newline; returned slice is a copy suitable for sending.

func ProtoDecode

func ProtoDecode(data []byte) (frames.Frame, error)

ProtoDecode decodes binary protobuf frame data into a Frame.

func ProtoDecoder

func ProtoDecoder(data []byte) (frames.Frame, error)

ProtoDecoder decodes a binary envelope (wire.FrameEnvelope) into a Frame.

func ProtoEncode

func ProtoEncode(f frames.Frame) ([]byte, error)

ProtoEncode encodes a Frame to binary protobuf format (wire-compatible with common frame schemas). Returns nil, nil if the frame type is not serializable in this format.

func ProtoEncoder

func ProtoEncoder(f frames.Frame) ([]byte, error)

ProtoEncoder encodes a Frame to binary envelope format (wire.FrameEnvelope: type + payload). Payload is the JSON-encoded frame body.

func ReadProtoEnvelope

func ReadProtoEnvelope(r io.Reader) (frames.Frame, error)

ReadProtoEnvelope reads one length-prefixed envelope from r (varint length + FrameEnvelope bytes) and decodes it to a Frame.

Types

type Envelope

type Envelope struct {
	Type string          `json:"type"`
	Data json.RawMessage `json:"data"`
}

Envelope is the JSON envelope for wire format (type + payload).

type JSONSerializer

type JSONSerializer struct{}

JSONSerializer uses the JSON envelope format (type + data).

func (JSONSerializer) Deserialize

func (JSONSerializer) Deserialize(data []byte) (frames.Frame, error)

func (JSONSerializer) Serialize

func (JSONSerializer) Serialize(f frames.Frame) ([]byte, error)

type ProtobufSerializer

type ProtobufSerializer struct{}

ProtobufSerializer uses binary protobuf frame format. Unserializable frame types are skipped (Serialize returns nil, nil).

func (ProtobufSerializer) Deserialize

func (ProtobufSerializer) Deserialize(data []byte) (frames.Frame, error)

func (ProtobufSerializer) Serialize

func (ProtobufSerializer) Serialize(f frames.Frame) ([]byte, error)

type Serializer

type Serializer interface {
	Serialize(f frames.Frame) ([]byte, error)
	Deserialize(data []byte) (frames.Frame, error)
}

Serializer converts frames to/from wire format (e.g. JSON envelope or binary protobuf).

type SerializerWithMessageType

type SerializerWithMessageType interface {
	Serializer
	SerializeWithType(f frames.Frame) (data []byte, binary bool, err error)
}

SerializerWithMessageType is an optional interface. When implemented, SerializeWithType is used instead of Serialize, and the returned binary flag selects WebSocket text vs binary (e.g. Vonage: audio = binary, JSON events = text).

type SerializerWithSetup

type SerializerWithSetup interface {
	Setup(start *frames.StartFrame)
}

SerializerWithSetup is an optional interface. When implemented, Setup is called when a StartFrame is received so the serializer can read AudioInSampleRate/AudioOutSampleRate.

Directories

Path Synopsis
Package exotel provides Exotel Media Streams WebSocket protocol serializer.
Package exotel provides Exotel Media Streams WebSocket protocol serializer.
Package genesys provides Genesys AudioHook WebSocket protocol serializer.
Package genesys provides Genesys AudioHook WebSocket protocol serializer.
Package plivo provides Plivo Audio Streaming WebSocket protocol serializer.
Package plivo provides Plivo Audio Streaming WebSocket protocol serializer.
Package telnyx provides Telnyx WebSocket protocol serializer.
Package telnyx provides Telnyx WebSocket protocol serializer.
Package twilio provides Twilio Media Streams WebSocket protocol serializer.
Package twilio provides Twilio Media Streams WebSocket protocol serializer.
Package vonage provides Vonage Audio Connector WebSocket serializer.
Package vonage provides Vonage Audio Connector WebSocket serializer.

Jump to

Keyboard shortcuts

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