https://github.com/lujjjh/go-javaio
Go implementation of Java Object Serialization Stream Protocol.
https://github.com/lujjjh/go-javaio
go golang java serialization
Last synced: 18 days ago
JSON representation
Go implementation of Java Object Serialization Stream Protocol.
- Host: GitHub
- URL: https://github.com/lujjjh/go-javaio
- Owner: lujjjh
- License: mit
- Created: 2019-06-03T12:42:02.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-06-18T09:46:12.000Z (almost 5 years ago)
- Last Synced: 2025-05-07T09:15:43.705Z (18 days ago)
- Topics: go, golang, java, serialization
- Language: Go
- Size: 89.8 KB
- Stars: 8
- Watchers: 0
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-javaio
## Get Started
```sh
go get github.com/lujjjh/go-javaio/...
````struct`s 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:
```go
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:
```go
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:
```go
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
- [x] Serialization
- [x] Deserialization