Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
529ddaa
feat: added encoding and decoding functions for bool, uint8, int8, fl…
fatmaebrahim Sep 14, 2025
e845095
feat: added encoding and decoding functions for string8, string16, st…
fatmaebrahim Sep 14, 2025
79862d0
feat: added nil and 16,32,64 int and uint
fatmaebrahim Sep 14, 2025
38d695f
feat: added array encoding function
fatmaebrahim Sep 15, 2025
ff14fa7
feat: added deserializeElement function for decoding different formats
fatmaebrahim Sep 15, 2025
3da2fa4
feat: added encoding and decoding functions for map
fatmaebrahim Sep 15, 2025
3622316
feat: added pack and unpack functions
fatmaebrahim Sep 15, 2025
6af3bba
fix: handled objects in unpack
fatmaebrahim Sep 16, 2025
e620aca
test: added unit tests for string8/16/32
fatmaebrahim Sep 16, 2025
a52f7fd
test: added unit tests for uint8/16/32/64 int8/16/32/64 float32/64
fatmaebrahim Sep 16, 2025
a658010
test: added unit tests for array16/32 map/16/32
fatmaebrahim Sep 16, 2025
d82826b
test: added unit tests for complex struct
fatmaebrahim Sep 16, 2025
74f218a
feat: added serialize and deserialize functions
fatmaebrahim Sep 16, 2025
a73c5c7
refactor: used serialize instead of pack for unit tests
fatmaebrahim Sep 16, 2025
0e22e50
docs: added functions documentation
fatmaebrahim Sep 16, 2025
11ac409
fix: handled typed mapped in serialize and deserialize
fatmaebrahim Sep 17, 2025
4f9e2e2
fix: handled typed map in unpack
fatmaebrahim Sep 17, 2025
a11bb3b
feat: handled binary types
fatmaebrahim Sep 17, 2025
b426b9e
fix: handled typed array in unpack
fatmaebrahim Sep 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 65 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,66 @@
# Msgpack-Fatma-Ebrahim
a Go package that implements MessagePack serialization and deserialization.
a Go library that implements MessagePack serialization and deserialization.

Check this link to learn more: https://github.com/msgpack/msgpack/blob/master/spec.md

## Functions:
### `Serialize(elementVal any) []byte`
serializes a single element into a byte array

### `Deserialize(value []byte) any`
deserializes a byte array into a single element

### `Pack(obj interface{}) ([]byte, error)`
packs an object into a byte array

### `Unpack(bytes []byte, obj interface{}) (any, error)`
unpacks a byte array into an object


## How to Use:
### Step 1: Install the library using `go get`

```bash
go get github.com/codescalersinternships/Msgpack-Fatma-Ebrahim
```

This command fetches the library and adds it to your project's `go.mod` file.

### Step 2: Import and use the library in your code

After running `go get`, you can import the library into your project and use the functions as described:


```
package main

import (
"fmt"
msgpack "github.com/codescalersinternships/Msgpack-Fatma-Ebrahim/pkg"
)

type Object struct {
IsObject bool
Flag bool
}

func main() {
object := Object{
IsObject: true,
Flag: false,
}

packed, err := msgpack.Pack(object)
if err != nil {
fmt.Println(err)
}

var obj Object
_, err = msgpack.Unpack(packed, &obj)
if err != nil {
fmt.Println(err)
}

fmt.Printf("Object: %+v\n", obj)
}
```
61 changes: 61 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import (
"fmt"
msgpack "github.com/codescalersinternships/Msgpack-Fatma-Ebrahim/pkg"
)

func main() {
arr := make([]float32, 3)
arr[0] = 0
arr[1] = 7.1
arr[2] = 9.8

m := make(map[any]any)
m["hello"] = 10
m["world"] = -20

typed_map := make(map[float32]int16)
typed_map[1.1] = 1
typed_map[2.2] = 2

object := msgpack.Object{
IsObject: true,
Flag: false,
Unum: 0,
Snum: -1000,
Fnum: 3.14,
Str: "Fatma",
Arr: arr,
Mapp: m,
Typed: typed_map,
}

packed, err := msgpack.Pack(object)
if err != nil {
fmt.Println(err)
}
fmt.Printf("Packed: %+v\n", packed)

var obj msgpack.Object
unpacked, err := msgpack.Unpack(packed, &obj)
if err != nil {
fmt.Println(err)
}
unpacked_val := unpacked.(map[any]any)
fmt.Printf("Unpacked: %+v\n", unpacked_val["Typed"])

fmt.Printf("object: %+v\n", obj)

bytes := make([]float32, 3)
bytes[0] = 1.1
bytes[1] = 2.2
bytes[2] = 3.3

ser := msgpack.Serialize(bytes)
fmt.Printf("Serialized: %+v\n", ser)

des := msgpack.Deserialize(ser)
fmt.Printf("Deserialized: %+v\n", des)

}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/codescalersinternships/Msgpack-Fatma-Ebrahim

go 1.25.1
Loading