github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/docs/msgp.md (about) 1 --- 2 layout: post 3 title: MSGPACK 4 permalink: /docs/msgp 5 redirect_from: 6 - /msgp.md/ 7 - /docs/msgp.md/ 8 --- 9 10 ## Table of Contents 11 12 - [Introduction](#introduction) 13 - [Code generation](#code-generation) 14 15 ## Introduction 16 17 MsgPack (aka "MessagePack") is a binary exchange format that provides better performance and lower bandwidth usage comparing to JSON. 18 To make a struct MsgPack-compatible, add tags to the struct in the same way you add JSON tags. 19 20 Example from `cmn/objlist.go`: 21 22 ```go 23 type LsObjEntry struct { 24 Name string `json:"name" msg:"n"` 25 Size int64 `json:"size,string,omitempty" msg:"s,omitempty"` 26 // the rest struct fields 27 ``` 28 29 Note `msg:"n"` tag value - in the resulting binary data, the field `Name` is marked with `n` title. 30 31 ## Code generation 32 33 After you change a struct that supports MsgPack, encoding and decoding functions are not updated automatically. 34 You have to run MsgPack generator for the changed file. 35 36 First, install the generator if you haven't done it yet: 37 38 ```console 39 $ make msgp-update 40 ``` 41 42 Second, generate the encoding and decoding functions. 43 For better compatibility and to minimize the diff size, use the same flags as in the example: 44 45 ```console 46 $ msgp -file <PATH_TO_CHANGED_FILE> -tests=false -marshal=false -unexported 47 ``` 48 49 When the generation completes, `msgp` creates a file with the original name and `_gen` prefix. 50 Do not forget to prepend a common AIS header to the generated file and commit it to the repository. 51 52 Workflow example: 53 54 ```console 55 $ ls cmn/objlist* 56 objlist.go 57 $ msgp -file cmn/objlist.go -tests=false -marshal=false -unexported 58 59 $ ls cmn/objlist* 60 objlist.go objlist.go 61 ```