Gentee
  • Gentee script programming language
  • Language Reference
    • Lexical elements
    • Types
    • Declarations
    • Statements
    • Error handling
    • Expressions
    • Running programs
    • Multithreading
    • Include and import
  • Standard Library Reference
    • Archiving
    • Array
    • Boolean
    • Buffer
    • Characters
    • Console
    • Constants
    • Context
    • Cryptography
    • Encoding
    • Files
    • Float numbers
    • Integer
    • Map
    • Multithreading
    • Network
    • Object
    • Path
    • Process
    • Regular expressions
    • Runtime
    • Sets
    • Strings
    • System
    • Time
  • Go Integration
    • Reference
    • Compilation and execution
    • Advanced features
    • Playground
  • Change language
    • Русский
Powered by GitBook
On this page
  • Functions
  • Json( obj o ) str
  • JsonToObj( str s ) obj
  • StructDecode( buf b, struct s )
  • StructEncode( struct s ) buf

Was this helpful?

  1. Standard Library Reference

Encoding

PreviousCryptographyNextFiles

Last updated 4 years ago

Was this helpful?

The functions for converting data from one format to another are described here.

Functions

Json( obj o ) str

The Json function converts a variable of obj type into json string.

JsonToObj( str s ) obj

The JsonToObj function converts json string into a variable of the obj type.

run str {
  return Json(JsonToObj(`{
         "int": 1234,
         "str": "value",
         "float": -45.67,
          "list":[{"on": true},
            "sub 2",
            "sub 3",
            {
                "q": "OK"
            }]
    }`))
}
// Result {"float":-45.67,"int":1234,"list":[{"on":true},"sub 2","sub 3",{"q":"OK"}],"str":"value"}

StructDecode( buf b, struct s )

The StructDecode function converts the binary data of a buf variable to the field values of the specified structure variable. The binary data must be created with StructEncode function.

  time t
  StructDecode(StructEncode(Now()), t)

StructEncode( struct s ) buf

The StructEncode function converts a structure variable to binary and stores the result into a buf variable. The function saves only fields of the following types: int, bool, char, float, buf, str. Fields of other types are skipped.

struct tmp {
    str head
    int i
}

run str {
  tmp t1 = {head: `HEADER`, i: -356}
  buf bout = StructEncode(t1)
  ...
}
Json( obj o ) str
JsonToObj( str s ) obj
StructDecode( b buf, struct s )
StructEncode( struct s ) buf