marshal

package
v0.0.0-...-b0deb01 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Constructor

func Constructor(ot ObjectType) func() interface{}

Constructor returns the constructor for an object type.

func RegisterCtor

func RegisterCtor(ot ObjectType, ctor func() interface{})

Registers a constructor for an object.

func SetInsertFunction

func SetInsertFunction(fn func(interface{}))

SetInsertFunction sets the function that inserts objects into the datastore

Types

type Marshaler

type Marshaler interface {
	// Serial returns the uo.Serial value identifying this object.
	Serial() uo.Serial
	// Marshal writes the binary representation of the object to the segment.
	Marshal(*TagFileSegment)
	// ObjectType returns the ObjectType associated with this struct.
	ObjectType() ObjectType
	// TemplateName returns the string describing what template the object was
	// constructed from.
	TemplateName() string
}

Marshaler is an object that knows how to marshal itself into a binary format.

type ObjectType

type ObjectType byte

ObjectType are the concrete Go types in the game package.

const (
	ObjectTypeObject            ObjectType = 0  // BaseObject
	ObjectTypeStatic            ObjectType = 1  // StaticItem
	ObjectTypeItem              ObjectType = 2  // BaseItem
	ObjectTypeWearable          ObjectType = 3  // BaseWearable
	ObjectTypeWearableContainer ObjectType = 4  // WearableContainer
	ObjectTypeWeapon            ObjectType = 5  // BaseWeapon
	ObjectTypeContainer         ObjectType = 6  // BaseContainer
	ObjectTypeMountItem         ObjectType = 7  // MountItem
	ObjectTypeMobile            ObjectType = 8  // BaseMobile
	ObjectTypeAccount           ObjectType = 9  // Account
	ObjectTypeSpawner           ObjectType = 10 // Spawner
	ObjectTypeDoor              ObjectType = 11 // Door
	ObjectTypeCheck             ObjectType = 12 // Check
)

type Segment

type Segment byte

Segment represents a segment name within a file

const (
	SegmentAccounts     Segment = 0
	SegmentMap          Segment = 1
	SegmentTimers       Segment = 2
	SegmentWorld        Segment = 3
	SegmentObjectList   Segment = 4
	SegmentDeepStorage  Segment = 5
	SegmentObjectsStart Segment = 0x7F // THIS MUST BE THE LAST ENTRY!
)

Segment values

type TagFile

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

TagFile manages an object database in-memory.

Encoding formats:

A tag file consist of a series of segments. Each segment is treated as a binary blob within the file structure. It's exact encoding is determined by the application at run-time.

File Format: MagicString uint64 A fixed value used to identify this as a ShardUO TagFile: 0x6BB50D00B87E33A4 SegmentCount uint8 Number of segments in the file Headers []SegmentHeader Segment headers Blob []byte Raw segment data

Segment Header: ID uint8 Unique identifier of the segment Offset uint64 Offset from the beginning of the file where the raw segment data starts Length uint64 Length of the raw segment data Records uint32 Number of records in the segment

func NewTagFile

func NewTagFile(d []byte) *TagFile

NewTagFile creates a new TagFile object from the data given. The data slice may be nil, in which case an empty TagFile object is returned ready for write operations.

func (*TagFile) Close

func (f *TagFile) Close()

Close releases internal memory and MUST be called!

func (*TagFile) Output

func (f *TagFile) Output(w io.Writer)

Output writes the file to the writer in TagFile format.

func (*TagFile) Segment

func (f *TagFile) Segment(which Segment) *TagFileSegment

Segment returns the named segment. A new, empty segment is created if needed.

type TagFileSegment

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

TagFileSegment manages a single segment in the file.

func NewTagFileSegment

func NewTagFileSegment(id Segment, parent *TagFile) *TagFileSegment

NewTagFileSegment returns an initialized TagFile object.

func (*TagFileSegment) Bool

func (s *TagFileSegment) Bool() bool

Bool returns the next 8-bit number as a boolean, any value other than 0 is returned as true

func (*TagFileSegment) Bounds

func (s *TagFileSegment) Bounds() uo.Bounds

Bounds returns the next uo.Bounds value encoded into the segment.

func (*TagFileSegment) Byte

func (s *TagFileSegment) Byte() byte

Byte returns the next 8-bit number in the segment

func (*TagFileSegment) Float

func (s *TagFileSegment) Float() float64

Float returns the next 64-bit float in the segment

func (*TagFileSegment) IncrementRecordCount

func (s *TagFileSegment) IncrementRecordCount()

IncrementRecordCount increments the record count of the segment by one.

func (*TagFileSegment) Int

func (s *TagFileSegment) Int() uint32

Int returns the next 32-bit number in the segment

func (*TagFileSegment) IsEmpty

func (s *TagFileSegment) IsEmpty() bool

IsEmpty returns true if the segment contains no data.

func (*TagFileSegment) Location

func (s *TagFileSegment) Location() uo.Location

Location returns the next uo.Location value encoded into the segment.

func (*TagFileSegment) Long

func (s *TagFileSegment) Long() uint64

Long returns the next 64-bit number in the segment

func (*TagFileSegment) Object

func (s *TagFileSegment) Object() Unmarshaler

Object returns the next object encoded into the segment which must support the Unmarshaler interface. The object will be fully unmarshaled upon return.

func (*TagFileSegment) ObjectReferences

func (s *TagFileSegment) ObjectReferences() []uo.Serial

ObjectReferences returns the next []uo.Serial encoded into the segment.

func (*TagFileSegment) PutBool

func (s *TagFileSegment) PutBool(v bool)

PutBool writes a single 8-bit value to the segment based on the value of v.

func (*TagFileSegment) PutBounds

func (s *TagFileSegment) PutBounds(b uo.Bounds)

PutBounds writes a bounds value to the segment as a tuple of int16,int16,int16,int16

func (*TagFileSegment) PutByte

func (s *TagFileSegment) PutByte(v byte)

PutByte writes a single 8-bit value to the segment.

func (*TagFileSegment) PutFloat

func (s *TagFileSegment) PutFloat(v float64)

PutFloat writes a single 64-bit float value to the segment.

func (*TagFileSegment) PutInt

func (s *TagFileSegment) PutInt(v uint32)

PutInt writes a single 32-bit value to the segment.

func (*TagFileSegment) PutLocation

func (s *TagFileSegment) PutLocation(l uo.Location)

PutLocation writes a location value to the segment as a tuple of int16,int16,int8.

func (*TagFileSegment) PutLong

func (s *TagFileSegment) PutLong(v uint64)

PutLong writes a single 64-bit value to the segment.

func (*TagFileSegment) PutObject

func (s *TagFileSegment) PutObject(o Marshaler)

PutObject writes an object to the segment.

func (*TagFileSegment) PutObjectReferences

func (s *TagFileSegment) PutObjectReferences(serials []uo.Serial)

PutObjectReferences writes all of the serials from the given slice as 32-bit object references to the tag file segment preceded by the count of references (8-bit value).

func (*TagFileSegment) PutSerialSlice

func (s *TagFileSegment) PutSerialSlice(v []uo.Serial)

PutSerialSlice writes all of the values in the slice to the segment preceded by the number of shorts (8-bit value).

func (*TagFileSegment) PutShort

func (s *TagFileSegment) PutShort(v uint16)

PutShort writes a single 16-bit value to the segment.

func (*TagFileSegment) PutShortSlice

func (s *TagFileSegment) PutShortSlice(v []int16)

PutShortSlice writes all of the values in the slice to the segment preceded by the number of shorts (8-bit value).

func (*TagFileSegment) PutString

func (s *TagFileSegment) PutString(v string)

PutString writes a 32-bit string reference value to the segment, and inserts the string into the dictionary if needed.

func (*TagFileSegment) PutStringsMap

func (s *TagFileSegment) PutStringsMap(m map[string]string)

PutStringsMap writes a sequential list of strings from the map in key, value pairs preceded by the count of pairs (16-bit value).

func (*TagFileSegment) RecordCount

func (s *TagFileSegment) RecordCount() uint32

RecordCount returns the number of records encoded into the segment.

func (*TagFileSegment) SerialSlice

func (s *TagFileSegment) SerialSlice() []uo.Serial

SerialSlice returns the next []uo.Serial encoded into the segment.

func (*TagFileSegment) Short

func (s *TagFileSegment) Short() uint16

Short returns the next 16-bit number in the segment

func (*TagFileSegment) ShortSlice

func (s *TagFileSegment) ShortSlice() []int16

ShortSlice returns the next []int16 encoded into the segment.

func (*TagFileSegment) String

func (s *TagFileSegment) String() string

String returns the next UTF-8 string in the segment by reading a 32-bit string reference and indexing the tag file string dictionary.

func (*TagFileSegment) StringMap

func (s *TagFileSegment) StringMap() map[string]string

StringMap returns the next map[string]string encoded into the segment.

type Unmarshaler

type Unmarshaler interface {
	// SetSerial sets the uo.Serial value identifying this object.
	SetSerial(uo.Serial)
	// Unmarshal reads the binary representation of the object from the tag
	// object.
	Unmarshal(*TagFileSegment)
	// Deserialize takes data from the template object and initializes the
	// object's data structures with it.
	Deserialize(*template.Template, bool)
}

Unmarshaler is an object that knows how to unmarshal itself from binary.

Jump to

Keyboard shortcuts

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