Back to Top
View on GitHub Viant Engineering

GoHessian Usage Guide

A Practical Guide and Code Usage


Changelog

Usage
Guide

Home

Table of Contents

  1. Introduction
  2. Getting Ready to Go
  3. Installation
  4. Creating a New Go Hessian
  5. Using the GoHessian Serializer

1. Introduction and How to Use This Guide

GoHessian is simple to use, and can quickly be deployed for use in a varity of situations, ranging from basic encoding and decoding to integration into different projects.

This manual will take a look into GoHessian's Go API and general usage.

In our examples, we will assume a few things:

2. Getting Ready To Go

To use GoHessian, you'll need Go. Setting up your Go enviroment is very simple.

3. Installation

4. Creating a New Instance of GoHessian

5. Using the GoHessian Serializer

There are two important methods in the serializer--ToBytes and ToObject--that carry out opposite tasks, which are encoding and decoding the data, respectively. Passing an object to ToBytes will produce a byte array, and passing the byte array to ToObject will produce the original object. Assume we create a struct as such:


          type Person struct {
            firstName string
            lastName string
        }
        
Now, we'll create a Person object and encode, then decode, the object:

        person := Person{"John","Doe"}
        gh := NewGoHessian(nil, nil)
        byteArray, _ := gh.ToBytes(p)
        same_person, _ := gh.ToObject(bt)
      
Here, person is an instance of struct Person, gh is our GoHessian instance, and byteArray is the value of the Person after it has been encoded. To decode the Person, the byteArray is passed to ToObject, which returns an object that has the same value as person.