tlv

package module
v0.0.0-...-6cd014e Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2016 License: MIT Imports: 5 Imported by: 0

README

TLV

GoDoc

TLV is the representative of type-length-value.

It might be found in a binary file format or a network protocol.

Brief

One TLV Object:

 1 Byte   4 Bytes  $Length Bytes
+-------+---------+-------------+
| Type  | Length  |    Value    |
+-------+---------+-------------+

Serial TLV Objects:

 1 Byte   4 Bytes  $Length Bytes 1 Byte   4 Bytes  $Length Bytes
+-------+---------+-------------+-------+---------+-------------+
| Type  | Length  |    Value    | Type  | Length  |    Value    | ...
+-------+---------+-------------+-------+---------+-------------+

Embedded TLV Objects:

 1 Byte   4 Bytes          $Length Bytes
                   1 Byte   4 Bytes  $Length Bytes
+-------+---------+-------+---------+-------------+
| Type  | Length  | Type  | Length  |    Value    |
+-------+---------+-------+---------+-------------+

Wireshark Plugin

  • Put wssdl and tlv.lua to ~/.config/wireshark/plugins
  • The UDP port 8327 will be decoded as tlv protocol.

Documentation

Overview

Package tlv provides a toolkit for working with TLV (Type-Length-Value) objects and TLV object List.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTLVRead is returned when there is an error reading a TLV object.
	ErrTLVRead = fmt.Errorf("TLV %s", "read error")
	// ErrTLVWrite is returned when  there is an error writing a TLV object.
	ErrTLVWrite = fmt.Errorf("TLV %s", "write error")
	// ErrTypeNotFound is returned when a request for a TLV type is made and none can be found.
	ErrTypeNotFound = fmt.Errorf("TLV %s", "type not found")
)

Functions

func Equal

func Equal(tlv1, tlv2 TLV) bool

Equal returns true if a pair of TLV objects are the same.

func ToBytes

func ToBytes(tlv TLV) ([]byte, error)

ToBytes returns bytes from a TLV object

func WriteObject

func WriteObject(tlv TLV, w io.Writer) error

WriteObject writes a TLV object to io.Writer

Types

type List

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

List is ad double-linked list containing TLV objects.

func NewList

func NewList() *List

NewList returns a new, empty TLVList.

func Read

func Read(r io.Reader) (*List, error)

Read takes an io.Reader and builds a TLVList from that.

func (*List) Add

func (tl *List) Add(typ byte, value []byte)

Add pushes a new TLV object onto the TLVList. It builds the object from its args

func (*List) AddObject

func (tl *List) AddObject(obj TLV)

AddObject adds a TLV object onto the TLVList

func (*List) Get

func (tl *List) Get(typ byte) (TLV, error)

Get checks the TLVList for any object matching the type, It returns the first one found. If the type could not be found, Get returns ErrTypeNotFound.

func (*List) GetAll

func (tl *List) GetAll(typ byte) []TLV

GetAll checks the TLVList for all objects matching the type, returning a slice containing all matching objects. If no object has the requested type, an empty slice is returned.

func (*List) Length

func (tl *List) Length() int32

Length returns the number of objects int the TLVList.

func (*List) Remove

func (tl *List) Remove(typ byte) int

Remove removes all objects with the requested type. It returns a count of the number of removed objects.

func (*List) RemoveObject

func (tl *List) RemoveObject(obj TLV) int

RemoveObject takes an TLV object as an argument, and removes all matching objects. It matches on not just type, but also the value contained in the object.

func (*List) Write

func (tl *List) Write(w io.Writer) error

Write writes out the TLVList to an io.Writer.

type TLV

type TLV interface {
	Type() byte
	Length() int32
	Value() []byte
}

TLV represents a Type-Length-Value object.

func FromBytes

func FromBytes(data []byte) (TLV, error)

FromBytes returns a TLV object from bytes

func New

func New(typ byte, val []byte) TLV

New returns a TLV object from the args

func ReadObject

func ReadObject(r io.Reader) (TLV, error)

ReadObject returns a TLV object from io.Reader

Jump to

Keyboard shortcuts

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