javaio

package module
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2020 License: MIT Imports: 11 Imported by: 0

README

go-javaio

Get Started

go get github.com/lujjjh/go-javaio/...

structs to be serialized must implements ClassName() string method which returns the Java class name.

Optionally, SerialVersionUID() int64 may be implemented if you want to specify the serialVersionUID of the class.

For example, define a List struct:

type List struct {
	Value int32
	Next  *List
}

func (*List) ClassName() string {
	return "List"
}

func (*List) SerialVersionUID() int64 {
	return 1
}

Create List instances and serialize them:

list2 := &List{
    Value: 19,
}
list1 := &List{
    Value: 17,
    Next:  list2,
}

var buf bytes.Buffer
w, _ := NewStreamWriter(&buf)
w.writeObject(list1)
w.writeObject(list2)

The resulting buffer contains:

00000000  ac ed 00 05 73 72 00 04  4c 69 73 74 00 00 00 00  |....sr..List....|
00000010  00 00 00 01 02 00 02 49  00 05 76 61 6c 75 65 4c  |.......I..valueL|
00000020  00 04 6e 65 78 74 74 00  06 4c 4c 69 73 74 3b 78  |..nextt..LList;x|
00000030  70 00 00 00 11 73 71 00  7e 00 00 00 00 00 13 70  |p....sq.~......p|
00000040  71 00 7e 00 03                                    |q.~..|

Features

  • Serialization
  • Deserialization

Documentation

Index

Constants

View Source
const (
	StreamMagic      uint16 = 0xaced
	StreamVersion    int16  = 5
	TcNull           byte   = 0x70
	TcReference      byte   = 0x71
	TcClassdesc      byte   = 0x72
	TcObject         byte   = 0x73
	TcString         byte   = 0x74
	TcArray          byte   = 0x75
	TcClass          byte   = 0x76
	TcBlockdata      byte   = 0x77
	TcEndblockdata   byte   = 0x78
	TcReset          byte   = 0x79
	TcBlockdatalong  byte   = 0x7A
	TcException      byte   = 0x7B
	TcLongstring     byte   = 0x7C
	TcProxyclassdesc byte   = 0x7D
	TcEnum           byte   = 0x7E
)

The following symbols in `java.io.ObjectStreamConstants` define the terminal and constant values expected in a stream.

View Source
const (
	ScWriteMethod    byte = 0x01 // if SC_SERIALIZABLE
	ScBlockData      byte = 0x08 // if SC_EXTERNALIZABLE
	ScSerializable   byte = 0x02
	ScExternalizable byte = 0x04
	ScEnum           byte = 0x10
)

The flag byte classDescFlags may include values of

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

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

func NewArray

func NewArray(x interface{}) *Array

func (*Array) ClassName

func (array *Array) ClassName() string

func (*Array) Index

func (array *Array) Index(i int) interface{}

func (*Array) Len

func (array *Array) Len() int

func (*Array) SerialVersionUID

func (array *Array) SerialVersionUID() int64

type Decoder

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

func NewDecoder

func NewDecoder(r io.Reader) (*Decoder, error)

func (*Decoder) DefaultReadFields added in v0.2.3

func (dec *Decoder) DefaultReadFields() (err error)

func (*Decoder) Read

func (dec *Decoder) Read(p []byte) (int, error)

func (*Decoder) ReadBinary added in v0.2.2

func (dec *Decoder) ReadBinary(dsts ...interface{}) error

func (*Decoder) ReadObject

func (dec *Decoder) ReadObject() (interface{}, error)

func (*Decoder) RegisterType

func (dec *Decoder) RegisterType(name string, typ reflect.Type)

type Encoder

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

func NewEncoder

func NewEncoder(w io.Writer) (*Encoder, error)

func (*Encoder) Write

func (enc *Encoder) Write(p []byte) (int, error)

func (*Encoder) WriteObject

func (enc *Encoder) WriteObject(object interface{}) error

type Field

type Field struct {
	Name  string
	Typ   reflect.Type
	Value reflect.Value
}

type ObjectReader added in v0.2.2

type ObjectReader interface {
	ReadObject(dec *Decoder) error
}

type ObjectWriter

type ObjectWriter interface {
	WriteObject(enc *Encoder) error
}

type Serializable

type Serializable struct {
	Value interface{} `javaio:"-"`
}

func (Serializable) ClassName

func (Serializable) ClassName() string

func (Serializable) SerialVersionUID

func (Serializable) SerialVersionUID() int64

type String

type String struct {
	Value string `javaio:"-"`
}

func (String) ClassName

func (String) ClassName() string

func (String) SerialVersionUID

func (String) SerialVersionUID() int64

Jump to

Keyboard shortcuts

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