GithubHelp home page GithubHelp logo

gamf's Introduction

English | δΈ­ζ–‡

gamf

Best open source lib of AMF serialization and deserialization based on Go.

Features

  • Usage exactly similar to std.json
  • Flexible customization with options
  • More compatible, we supported both AMF0 & AMF3

Installation

go get github.com/gnolizuh/gamf

How to use

Integer

AMF0

in := 1
bs, _ := Marshal(&in)

var out int
Unmarshal(bs, &out)

AMF3

var bs []byte
buf := bytes.NewBuffer(bs)

in := 1
NewEncoder().WithWriter(buf).Encode(&in)

var out int
NewDecoder().WithReader(buf).Decode(&out)

Float

AMF0

in := 1.0
bs, _ := Marshal(&in)

var out float64
Unmarshal(bs, &out)

AMF3

var bs []byte
buf := bytes.NewBuffer(bs)

in := 1
NewEncoder().WithWriter(buf).WithVersion(Version3).Encode(&in)

var out int
NewDecoder().WithReader(buf).WithVersion(Version3).Decode(&out)

String

AMF0

in := "1"
bs, _ := Marshal(&in)

var out string
Unmarshal(bs, &out)

AMF3

var bs []byte
buf := bytes.NewBuffer(bs)

in := "1"
NewEncoder().WithWriter(buf).WithVersion(Version3).Encode(&in)

var out string
NewDecoder().WithReader(buf).WithVersion(Version3).Decode(&out)

Bool

AMF0

in := "1"
bs, _ := Marshal(&in)

var out string
Unmarshal(bs, &out)

AMF3

var bs []byte
buf := bytes.NewBuffer(bs)

in := true
NewEncoder().WithWriter(buf).WithVersion(Version3).Encode(&in)

out := false
NewDecoder().WithReader(buf).WithVersion(Version3).Decode(&out)

Slice

AMF0

in := []int{1, 2, 3}
bs, _ := Marshal(&in)

var out []int
Unmarshal(bs, &out)

AMF3

var bs []byte
buf := bytes.NewBuffer(bs)

in := []any{1.0, "1", true, map[string]any{"Int": 1.0, "String": "1", "Bool": true}}
NewEncoder().WithWriter(buf).WithVersion(Version3).Encode(&in)

out := []any{0.0, "0", false, map[string]any{}}
NewDecoder().WithReader(buf).WithVersion(Version3).Decode(&out)

Struct

Struct to Struct

type Struct struct {
    Int    int    `amf:"tag_int"`
    String string `amf:"tag_string"`
    Bool   bool   `amf:"tag_bool"`
    Object struct {
        Int    int    `amf:"tag_int"`
        String string `amf:"tag_string"`
        Bool   bool   `amf:"tag_bool"`
    } `amf:"tag_object"`
}

in := Struct{} // with value be initialized
bs, _ := Marshal(&in)

out := Struct{}
Unmarshal(bs, &out)

Struct to Map

type Struct struct {
    Int    int    `amf:"tag_int"`
    String string `amf:"tag_string"`
    Bool   bool   `amf:"tag_bool"`
    Object struct {
        Int    int    `amf:"tag_int"`
        String string `amf:"tag_string"`
        Bool   bool   `amf:"tag_bool"`
    } `amf:"tag_object"`
}

in := Struct{} // with value be initialized
bs, _ := Marshal(&in)

out := make(map[string]any)
Unmarshal(bs, &out)

Map

in := map[string]any{"Int": 1.0, "String": "1", "Bool": true}
bs, _ := Marshal(&in)

out := make(map[string]any)
Unmarshal(bs, &out)

Reference

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.