I am trying to make communicate a Go server with a Rust client (and vice-versa), and to do so, I want to serialize (or Marshal as you would say in Go) a struct in order to send it. Here are my codes :
package main
import (
"fmt"
"github.com/vmihailenco/msgpack/v5"
)
func ExampleMarshal() {
type Human struct {
Age byte
}
var x = Human{Age: 42}
b, err := msgpack.Marshal(x)
if err != nil {
panic(err)
}
fmt.Println("b:", b)
}
func main () {
ExampleMarshal()
} // took from https://github.com/vmihailenco/msgpack
extern crate serde;
#[macro_use]
extern crate rmp_serde as rmps;
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use rmps::{Deserializer, Serializer};
#[derive(Debug, PartialEq, Deserialize, Serialize)]
struct Human {
age: u8,
}
fn main() {
let mut buf = Vec::new();
let val = Human {
age: 42,
};
val.serialize(&mut Serializer::new(&mut buf)).unwrap();
println!("{:?}", buf);
} // took from https://docs.rs/rmp-serde/latest/rmp_serde/
The problem is that with the exact same values, I don't get the same serialized value
- Go -> b: [129 163 65 103 101 204 42]
- Rust -> [145, 42]
Can someone explain me why I don't get the exact same values ? My goal is to have the Go Output the same as the Rust one