ndr

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

package ndr implements the NDR encoding.

Index

Constants

This section is empty.

Variables

View Source
var (
	// IEEE floating point representation.
	FloatingPointIEEE uint32 = 0x00000000
	// VAX floating point representation.
	FloatingPointVAX uint32 = 0x00000100
	// Cray floating point representation.
	FloatingPointCray uint32 = 0x00000200
	// IBM floating point representation.
	FloatingPointIBM uint32 = 0x00000300
	// Mask.
	FloatingPointMask uint32 = 0x0000FF00
)
View Source
var (
	// ASCII character representation.
	CharASCII uint32 = 0x00000000
	// EBCDIC character representation.
	CharEBCDIC uint32 = 0x00000001
	// Mask.
	CharMask uint32 = 0x0000000F
)
View Source
var (
	// Big-endian data representation.
	ByteOrderBigEndian uint32 = 0x00000000
	// Little-endian data representation.
	ByteOrderLittleEndian uint32 = 0x00000010
	// Mask.
	ByteOrderMask uint32 = 0x000000F0
)
View Source
var Debug debug
View Source
var (
	// The default data representation (ASCII, FloatIEEE, LittleEndian).
	DefaultDataRepresentation = DataRepresentation(CharASCII | FloatingPointIEEE | ByteOrderLittleEndian)
)
View Source
var Opaque opaque

Opaque is an NDR option that is used to indicate that implicit NDR data, like size labels, non-encapsulated switches, pointer values must be omitted. Any pointer deferred values must be encoded immediately.

View Source
var (
	// SizeInfoCtx is a context type for the size information.
	SizeInfo = SizeInfoCtx{}
)
View Source
var (
	// ZeroString represents the empty null-termination string.
	ZeroString = string([]byte{0})
)

Functions

func CharLen

func CharLen(s string) uint64

func CharNLen

func CharNLen(s string) uint64

func DataSize

func DataSize(d any) int

DataSize function returns the data size for the given value `d`.

func Marshal

func Marshal(d Marshaler, opts ...any) ([]byte, error)

Marshal function marshals the data `d` using NDR2.0 format.

func MultiSzLen

func MultiSzLen(s []string) uint64

func ReadCharNString

func ReadCharNString(ctx context.Context, r Reader, s *string) error

ReadUTF16NString ...

func ReadCharString

func ReadCharString(ctx context.Context, r Reader, s *string) error

ReadCharString ...

func ReadUTF16NString

func ReadUTF16NString(ctx context.Context, r Reader, s *string) error

ReadUTF16NString ...

func ReadUTF16String

func ReadUTF16String(ctx context.Context, r Reader, s *string) error

ReadUTF16NString ...

func UTF16Len

func UTF16Len(s string) uint64

func UTF16NLen

func UTF16NLen(s string) uint64

UTF16NLen function ...

func Unmarshal

func Unmarshal(b []byte, d Unmarshaler, opts ...any) error

Unmarshal function unmarshals the bytes `b` to the data `d` using NDR2.0 format.

func WriteCharNString

func WriteCharNString(ctx context.Context, w Writer, s string) error

func WriteCharString

func WriteCharString(ctx context.Context, w Writer, s string) error

func WriteUTF16NString

func WriteUTF16NString(ctx context.Context, w Writer, s string) error

WriteUTF16NString function ...

func WriteUTF16String

func WriteUTF16String(ctx context.Context, w Writer, s string) error

Types

type AlignBuffer

type AlignBuffer interface {
	// The chunked buffer interface.
	ChunkedBuffer
	// EOF function must return true if underlying chunk buffer
	// length is zero. (note that it must be used only with chunks
	// that contain of a single buffer).
	EOF() bool
	// Pos must contain the current position of the buffer over
	// multiple chunks. (can be used to set proper pointer values).
	Pos() int
	// SkipMod function must advance the read buffer up to the
	// modulo of integer parameter.
	SkipMod(int) error
	// FillMod function must fill the write buffer up to the
	// modulo of integer parameter.
	FillMod(int) error
}

AlignBuffer provides the alignment capabilities over the chunked buffer. Since chunked buffer can contain multiple chunks in the implementation, we need to keep track of current position in the stream.

func NewAlignBuffer

func NewAlignBuffer(chk ChunkedBuffer) AlignBuffer

NewAlignBuffer returns the new instance of aligned buffer.

type Buffer

type Buffer interface {
	// EOF function must returns `true` if there is no more
	// data in the buffer.
	EOF() bool
	// Len function must returns the number of bytes available
	// for read or number of written bytes.
	Len() int
	// Offset function must return current buffer position.
	Offset() int
	// Bytes function must return the buffer bytes.
	Bytes() []byte
	// WithBytes function assigns the buffer to the parameter
	// bytes.
	WithBytes([]byte) NDR
}

Buffer interface.

type ChunkedBuffer

type ChunkedBuffer interface {
	EOF() bool
	// Read/Write interface.
	io.ReadWriter
	// Len function must return the total length of the buffer.
	Len() int
	// ReadRepresentation function must read and configure the
	// representation for the current chunk.
	ReadRepresentation(*DataRepresentation) error
	// WriteRepresentation function must write and configure
	// the representation for the current chunk.
	WriteRepresentation(DataRepresentation) error
	// Order function must return the byte order for the chunk.
	Order() binary.ByteOrder
	// Float function must return the floating-point format for
	// the chunk.
	Float() math.FloatFormat
	// Bytes function must return the bytes in the current chunk.
	Bytes() []byte
}

ChunkedBuffer interface is aimed to provide an interface for reading the data input chunk by chunk thus enabling capabilities for reusing the same buffer within single network exchange involving multiple chunks.

func NewChunk

func NewChunk(b []byte, drep DataRepresentation) ChunkedBuffer

NewChunk function returns the new chunked buffer.

type DataRepresentation

type DataRepresentation uint32

The NDR data representation.

func (DataRepresentation) ByteOrder

func (d DataRepresentation) ByteOrder() binary.ByteOrder

ByteOrder function returns the byte order for the data representation.

func (DataRepresentation) FloatFormat

func (d DataRepresentation) FloatFormat() math.FloatFormat

FloatFormat function returns the floating-point format for the data representation.

type Error

type Error interface {
	// Err function must return the captured error.
	Err() error
	// SetError must set and returns the error.
	SetErr(error) error
}

Error(er) interface.

type Int3264

type Int3264 int64

Int3264 type ...

type MarshalNDRFunc

type MarshalNDRFunc func(context.Context, Writer) error

MarshalNDRFunc function ...

func (MarshalNDRFunc) MarshalNDR

func (f MarshalNDRFunc) MarshalNDR(ctx context.Context, w Writer) error

MarshalNDR function implements the Marshaler interface.

type Marshaler

type Marshaler interface {
	MarshalNDR(context.Context, Writer) error
}

Marshaler interface ...

type NDR

type NDR interface {
	// Writer.
	Writer
	// Reader.
	Reader
}

NDR interface ...

func NDR20

func NDR20(buf []byte, opts ...any) NDR

NDR20 function returns the NDR2.0 Marshaler/Unmarshaler.

type Operation

type Operation interface {
	// The operation number.
	OpNum() int
	// The operation name.
	OpName() string
	// The function to marshal the request parameters.
	MarshalNDRRequest(context.Context, Writer) error
	// The function to unmarshal the request parameters.
	UnmarshalNDRRequest(context.Context, Reader) error
	// The function to marshal the response fields.
	MarshalNDRResponse(context.Context, Writer) error
	// The function to unmarshal the response fields.
	UnmarshalNDRResponse(context.Context, Reader) error
}

The NDR operation.

type Pointer

type Pointer interface{}

Pointer interface represents the generic pointer.

type Reader

type Reader interface {

	// Reader is a generic I/O writer interface.
	io.Reader

	// Error to return an error.
	Error

	// Buffer.
	Buffer

	// Marshal function performs the NDR marshaling with pointer
	// resolution.
	Unmarshal(context.Context, Unmarshaler) error

	// ReadAlign function performs alignment of the output buffer.
	ReadAlign(int) error

	// ReadData will align and read the type as-is.
	// If type has alignment, it should align the data in the
	// UnmarshalNDR method, if it's the primitive type,
	// primitive type alignment will be used.
	ReadData(any) error

	// ReadSize function reads the maximum count, offset,
	// and actual count for arrays, strings, pipes.
	ReadSize(*uint64) error

	// ReadSwitch function reads the switch value for the union.
	ReadSwitch(any) error

	// ReadPointer function reads the implementation-specific pointer.
	// It receives the setter function in case if pointer is not null.
	ReadPointer(Pointer, func(any), ...Unmarshaler) error

	// ReadDeferred function reads all the deferred pointers.
	ReadDeferred() error
}

type SizeInfoCtx

type SizeInfoCtx struct{}

SizeInfoCtx is a context key type for the size information.

type Uint3264

type Uint3264 uint64

Uint3264 type ...

type UnmarshalNDRFunc

type UnmarshalNDRFunc func(context.Context, Reader) error

UnmarshalNDRFunc function ...

func (UnmarshalNDRFunc) UnmarshalNDR

func (f UnmarshalNDRFunc) UnmarshalNDR(ctx context.Context, w Reader) error

UnmarshalNDR function implements the Unmarshaler interface.

type Unmarshaler

type Unmarshaler interface {
	UnmarshalNDR(context.Context, Reader) error
}

Unmarshaler interface ...

type WaitChunk

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

WaitChunk structure represents the buffer that blocks until provided via `Wait` bytes will be exhausted either by read or by write or by the completion of the operation (Done is called).

func NewWaitChunk

func NewWaitChunk() *WaitChunk

func (*WaitChunk) Bytes

func (c *WaitChunk) Bytes() []byte

Bytes function returns the bytes written/not-yet-read for the chunk.

func (*WaitChunk) Close

func (c *WaitChunk) Close()

func (*WaitChunk) Done

func (c *WaitChunk) Done()

func (*WaitChunk) EOF

func (c *WaitChunk) EOF() bool

EOF function indicates whether the WaitChunk is completed.

func (*WaitChunk) Float

func (c *WaitChunk) Float() math.FloatFormat

Float function return the floating-point format for the buffer chunk.

func (*WaitChunk) Len

func (c *WaitChunk) Len() int

Len function returns the current WaitChunk remaining data. (used for sanity check).

func (*WaitChunk) Order

func (c *WaitChunk) Order() binary.ByteOrder

Order function returns the byte order for the buffer chunk.

func (*WaitChunk) Read

func (c *WaitChunk) Read(p []byte) (int, error)

Read function implements the io.Reader interface.

func (*WaitChunk) ReadRepresentation

func (c *WaitChunk) ReadRepresentation(drep *DataRepresentation) error

func (*WaitChunk) Wait

func (c *WaitChunk) Wait(b []byte, frmt DataRepresentation, maxLen int) int

func (*WaitChunk) Write

func (c *WaitChunk) Write(p []byte) (int, error)

Write function implements the io.Writer interface.

func (*WaitChunk) WriteRepresentation

func (c *WaitChunk) WriteRepresentation(drep DataRepresentation) error

type Writer

type Writer interface {

	// Writer is a generic I/O writer interface.
	io.Writer

	// Error to return an error.
	Error

	// Buffer.
	Buffer

	// Marshal function performs the NDR marshaling with pointer
	// resolution.
	Marshal(context.Context, Marshaler) ([]byte, error)

	// WriteAlign function performs alignment of the output buffer.
	WriteAlign(int) error

	// WriteData will write and align the type as-is.
	// If type implements align method, it will be used, if it's the
	// primitive type, primitive type alignment will be used.
	WriteData(any) error

	// WriteSize function writes the maximum count, offset,
	// and actual count for arrays, strings, pipes.
	WriteSize(uint64) error

	// WriteSwitch function writes the union switch.
	WriteSwitch(any) error

	// WritePointer function writes the implementation-specific pointer.
	// Optional data parameter will be used when the full pointer is used.
	WritePointer(Pointer, ...Marshaler) error

	// WriteDeferred function writes all the deferred pointers.
	WriteDeferred() error
}

Writer interface ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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