Giter VIP home page Giter VIP logo

go-cshared-examples's People

Contributors

dgv avatar digital-512 avatar dpurfield avatar hellcoderz avatar nikhilgk avatar r9y9 avatar sbinet avatar synodriver avatar titpetric avatar vladimirvivien avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-cshared-examples's Issues

Go type not supported in export: lingua.Language

I would like to call lingua-go functions from C++ code

I tried to generate h file and so file for this code ( following the indications found here: https://github.com/vladimirvivien/go-cshared-examples)

basic.go :

package main

import "C"

import (
        "github.com/pemistahl/lingua-go"
)

var lan lingua.Language

//export Langdetectfunct
func Langdetectfunct(text string) lingua.Language {

    detector := lingua.NewLanguageDetectorBuilder().
        FromAllLanguages().
        Build()

    if language, exists := detector.DetectLanguageOf(text); exists {
        lan = language
    }
    lan = lingua.English

    return lan

}

func main() {}

Doing:

raphy@raohy:~/go-lang-detect$ go build -o basic.so -buildmode=c-shared basic.go

I get :

raphy@raohy:~/go-lang-detect$ go build -o basic.so -buildmode=c-shared basic.go
# command-line-arguments
./basic.go:14:35: Go type not supported in export: lingua.Language

[Question] C# byte[] <---> GO []byte (return to C# and input to GO)

@Digital-512 I'd once again like to thank you for your thorough answer on my other question #26. Not only did you provide excellent examples, but you also complemented them with explanations so that I actually managed to learn something at the same time.

Now I wonder if I'd be too bold, to once again ask for your input.

I managed to use the examples in this repository, to provide int inputs from C# to the exported Go Add() function, and then return an int from that exported Go function to the C# code.

However, I need to be able to input a C# byte[] to an exported GO function expecting a []byte input. I also need to return a []byte from that exported Go function to a C# byte[].

Consider the below examples.

Go exported function (pseduo):

//export ReturnBytes
func InputAndReturnBytes(byteSlice []byte) []byte {
	// Process the byteSlice []byte input
	// return processedByteSlice
}

From C#, how would I input a byte[] to the byteSlice []byte argument? How would I assign the returned []byte/GoSlice to a byte[] in C#?

Looking at the generated header file for such an exported function:
extern __declspec(dllexport) GoSlice InputAndReturnBytes(GoSlice byteSlice);

One can see that it expects a GoSlice for the byteSlice input parameter, and returns a GoSlice.

I've tried in various ways, e.g.:

  • To input a C# byte[] using the GoSlice struct which is defined earlier (also in the examples of this repository).
  • Assign the returned GoSlice from the exported Go function to the C# GoSlice struct.

But unfortunately both to no avail.

I struggle on how to work with the byte array/slice between the two languages/interfaces.

I can see that in Go:

// byte is an alias for uint8 and is equivalent to uint8 in all ways. It is
// used, by convention, to distinguish byte values from 8-bit unsigned
// integer values.
type byte = uint8

And in the CGO generated header file, that typedef unsigned char GoUint8; is actually defined.

Perhaps I need to create a GoByte/GoUint8 struct of sorts in C#, and then put it in the GoSlice? I actually have no idea.

As you can see, I have no idea what I'm doing here. 🙄
Crossing my fingers you'll have some time over to shed some light. 🤞

[Question] C# string array to GO slice

Hi,

I've successfully used the C# example of:

public struct GoSlice
{
    public IntPtr data;
    public long len, cap;
    public GoSlice(IntPtr data, long len, long cap)
    {
        this.data = data;
        this.len = len;
        this.cap = cap;
    }
}

[DllImport(libName)]
public static extern void Sort(GoSlice a);

long[] data = { 77, 12, 5, 99, 28, 23 };
IntPtr data_ptr = Marshal.AllocHGlobal(Buffer.ByteLength(data));
Marshal.Copy(data, 0, data_ptr, data.Length);
var nums = new GoSlice(data_ptr, data.Length, data.Length);
Sort(nums);
Marshal.Copy(nums.data, data, 0, data.Length);

To be able to pass in a C# int array to a GO []int.

But how would I go on about passing a C# string array to a GO []string?

Let's say we have the following function in the GO code:

//export StringArray
func StringArray(strings []string) {
	for _, element := range strings {
		fmt.Println(element)
	}
}

How would I call this, similar as to the []int call above?

Any input is appreciated!

Error: Dynamic Linking Error: Win32 error 126 in client.js

I'm on Windows 10 x64 bit and I am getting this problem. I have the code copied exactly the same way except for the first four requirements because the old ones seemed to be deprecated

Error: Dynamic Linking Error: Win32 error 126

Coming from

var awesome = ffi.Library("./awesome.so", {
  Add: ["longlong", ["longlong", "longlong"]],
  Cosine: ["double", ["double"]],
  Sort: ["void", [GoSlice]],
  Log: ["longlong", [GoString]]
});

how execute csharp method from go c-shared library?

I tried use the a go library on csharp and use callbacks, but the application entire crash by the library with the error:
unexpected fault address 0xffffffffffffffff fatal error: fault [signal 0xc0000005 code=0x0 addr=0xffffffffffffffff pc=0x627ca9ab]

go code:

package main

import "C"
import "fmt"

type externFunc func(int)

//export Connect
func Connect(fn externFunc) {
    fmt.Println("fn ",fn)

    for i:= 0; i<3;i++{
       fn(10)
    }

} 

How is the way to execute callbacks with c-shared?

Any examples of libraries using this approach?

Thanks @vladimirvivien for your article and Github repository.

I was wondering if you know of any (popular) libraries that use this approach to allow that library to be used from many other languages?

When asking about this in the Go community, I'm getting a lot of fear and doubt that I shouldn't use c-shared libaries for that purpose. For example that the Go would expect to own the process it is running in, and any such attempt would be "fragile". What is your view on that?

How to pass java string array into golang&java list to golang slice

Hello, need your help

I use []string in golang now, so how to call it in java?

package main

import (
	"C"
	"fmt"
	"github.com/xuri/excelize/v2"
	"math/rand"
	"strconv"
)

func main() {
	var tableHeaderEn []string
	tableHeaderEn = []string{"Item", "Name", "Age", "Gender", "Project", "Time"}
	testTimeExcel2("Book3.xlsx", "Sheet1", tableHeaderEn)

	//go build -buildmode=c-shared -o excel_stream.dll
	//go build -ldflags "-s -w" -buildmode=c-shared -o excel_stream.dll excel_stream.go
}

//export testTimeExcel2
func testTimeExcel2(excelFilePath string, iterationName string, tableHeaderEn []string) {
	fmt.Println("Start generating test time excel.")
	var xlsx *excelize.File
	var err error
	if xlsx, err = excelize.OpenFile(excelFilePath); err != nil {
		xlsx = excelize.NewFile()
	}

	streamWriter, err := xlsx.NewStreamWriter(iterationName) //"Sheet1" Ctrl+Alt+Y
	if err != nil {
		fmt.Println(err)
	}

	//表头样式
	styleIdEn, err := xlsx.NewStyle(&excelize.Style{Font: &excelize.Font{Color: "#777777"}})
	if err != nil {
		fmt.Println(err)
	}

	styleIdCn, err := xlsx.NewStyle(&excelize.Style{Font: &excelize.Font{Bold: true, Family: "Times New Roman"}})
	if err != nil {
		fmt.Println(err)
	}

	//表头名称第一行
	//var tableHeaderEn []string
	//tableHeaderEn = []string{"Item", "Name", "Age", "Gender", "Project", "Time"}
	var rowIdEn = 1
	for index, item := range tableHeaderEn {
		if err := streamWriter.SetRow(cellLocation(index, rowIdEn), []interface{}{excelize.Cell{StyleID: styleIdEn, Value: item}}); err != nil {
			fmt.Println(err)
		}
	}

	//隐藏第一行
	err = xlsx.SetRowVisible(iterationName, rowIdEn, false)
	if err != nil {
		fmt.Println(err)
	}

	//表头名称第二行
	var tableHeaderCn []string
	tableHeaderCn = []string{"序号", "姓名", "年龄", "性别", "工程", "时长"}
	var rowIdCn = 2
	for index, item := range tableHeaderCn {
		if err := streamWriter.SetRow(cellLocation(index, rowIdCn), []interface{}{excelize.Cell{StyleID: styleIdCn, Value: item}}); err != nil {
			fmt.Println(err)
		}
	}

	//第三行开始
	for rowID := 3; rowID <= 10; rowID++ {
		row := make([]interface{}, 6)
		for colID := 0; colID < 6; colID++ {
			row[colID] = rand.Intn(640000)
		}
		cell, _ := excelize.CoordinatesToCellName(1, rowID)
		if err := streamWriter.SetRow(cell, row); err != nil {
			fmt.Println(err)
		}
	}

	index := xlsx.GetSheetIndex(iterationName)
	xlsx.SetActiveSheet(index)

	if err := streamWriter.Flush(); err != nil {
		fmt.Println(err)
	}

	fmt.Println("End generating test time excel.")
	if err := xlsx.SaveAs(excelFilePath); err != nil {
		fmt.Println(err)
	}
	//return //xlsx.SaveAs(excelFilePath)
}

// cellLocation get cell location with given column and row
func cellLocation(c int, r int) (cellLocation string) {
	sc := 'A'
	if c < 26 {
		cellLocation = string(int(sc)+c) + strconv.Itoa(r)
	} else {
		cellLocation = "A" + string(int(sc)+c-26) + strconv.Itoa(r)
	}
	return
}

excel_stream.h

/* Code generated by cmd/cgo; DO NOT EDIT. */

/* package strong-excelize/hellp */


#line 1 "cgo-builtin-export-prolog"

#include <stddef.h> /* for ptrdiff_t below */

#ifndef GO_CGO_EXPORT_PROLOGUE_H
#define GO_CGO_EXPORT_PROLOGUE_H

#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
#endif

#endif

/* Start of preamble from import "C" comments.  */




/* End of preamble from import "C" comments.  */


/* Start of boilerplate cgo prologue.  */
#line 1 "cgo-gcc-export-header-prolog"

#ifndef GO_CGO_PROLOGUE_H
#define GO_CGO_PROLOGUE_H

typedef signed char GoInt8;
typedef unsigned char GoUint8;
typedef short GoInt16;
typedef unsigned short GoUint16;
typedef int GoInt32;
typedef unsigned int GoUint32;
typedef long long GoInt64;
typedef unsigned long long GoUint64;
typedef GoInt64 GoInt;
typedef GoUint64 GoUint;
typedef __SIZE_TYPE__ GoUintptr;
typedef float GoFloat32;
typedef double GoFloat64;
typedef float _Complex GoComplex64;
typedef double _Complex GoComplex128;

/*
  static assertion to make sure the file is being used on architecture
  at least with matching size of GoInt.
*/
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];

#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef _GoString_ GoString;
#endif
typedef void *GoMap;
typedef void *GoChan;
typedef struct { void *t; void *v; } GoInterface;
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;

#endif

/* End of boilerplate cgo prologue.  */

#ifdef __cplusplus
extern "C" {
#endif

extern __declspec(dllexport) void testTimeExcel2(GoString excelFilePath, GoString iterationName, GoSlice tableHeaderEn);

#ifdef __cplusplus
}
#endif

Thanks again

how to use `GoInterface` struct in CGO?

like the code below:

t.go
//export testFunc
func testFunc() (a interface{}) {
 a = 100
 return
}
t.h
typedef struct { void *t; void *v; } GoInterface;
// ...
extern GoInterface testFunc();

we export a function through CGO like extern GoInterface testFunc();, how to call this from C or Lua or others? how to initialization and using a GoInterface in C, or in the Luajit FFI context?

loading go shared library from python on alpine report OSError: Error relocating ./cc.so: : initial-exec TLS resolves to dynamic definition in ./cc.so

/usr/src/app # go build -o cc.so -buildmode=c-shared main.go

/usr/src/app # readelf -d cc.so
Dynamic section at offset 0x10cd10 contains 22 entries: Tag Type Name/Value 0x0000000000000001 (NEEDED) Shared library: [libc.musl-x86_64.so.1] 0x0000000000000010 (SYMBOLIC) 0x0 0x000000000000000c (INIT) 0x42000 0x000000000000000d (FINI) 0x92ed9 0x0000000000000019 (INIT_ARRAY) 0xa2078 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes) 0x000000006ffffef5 (GNU_HASH) 0x270 0x0000000000000005 (STRTAB) 0xa50 0x0000000000000006 (SYMTAB) 0x378 0x000000000000000a (STRSZ) 1026 (bytes) 0x000000000000000b (SYMENT) 24 (bytes) 0x0000000000000003 (PLTGOT) 0x10deb0 0x0000000000000002 (PLTRELSZ) 720 (bytes) 0x0000000000000014 (PLTREL) RELA 0x0000000000000017 (JMPREL) 0x41a00 0x0000000000000007 (RELA) 0xe58 0x0000000000000008 (RELASZ) 265128 (bytes) 0x0000000000000009 (RELAENT) 24 (bytes) 0x000000000000001e (FLAGS) SYMBOLIC BIND_NOW STATIC_TLS 0x000000006ffffffb (FLAGS_1) Flags: NOW NODELETE 0x000000006ffffff9 (RELACOUNT) 11040 0x0000000000000000 (NULL) 0x0

/usr/src/app # python test.py
Traceback (most recent call last):

File "test.py", line 2, in

lib = ctypes.cdll.LoadLibrary('./cc.so')

File "/usr/lib/python2.7/ctypes/init.py", line 444, in LoadLibrary

return self._dlltype(name)

File "/usr/lib/python2.7/ctypes/init.py", line 366, in init

self._handle = _dlopen(self._name, mode)

OSError: Error relocating ./cc.so: : initial-exec TLS resolves to dynamic definition in ./cc.so

-buildmode=c-shared not supported on windows/amd64

Im using go 1.9.3 and just tried to do this with this simple file :

package main

import "C"
import (
	"fmt"
)

//export add
func add(a, b int) int {
	var sum int = a + b
	fmt.Println("DONE")
	return sum
}

func main() {}

But kept getting the error above. Is there any way to fix this? Am I using the wrong command?

[Question] - Pass struct/slice of structs from C# <---> Go

Hello once again @Digital-512

As mentioned in #27, I'm now seeking assistance for the task of passing a struct and also a slice of structs, from C# to a CGO exported function, and returning a struct and also a slice of structs, from a CGO exported function to the calling C# code.

Consider the following example struct in Go:

type Person struct {
	Name             string
	Hobbies          []string
	FavouriteNumbers []int
	Age              int
	Single           bool
}

Which is then called as a single struct or a slice of structs:

person := Person{
	Name:             "John",
	Hobbies:          []string{"Golf", "Hiking", "Outdoors "},
	FavouriteNumbers: []int{1, 2, 3},
	Age:              21,
	Single:           false,
}

people := []Person{
	{"John", []string{"Golf", "Hiking", "Outdoors "}, []int{1, 2, 3}, 21, false},
	{"Doe", []string{"Cycling"}, []int{4}, 32, false},
	// etc...
}

Building on top of your other provided snippets, what would be a suitable way of doing this?
How would I go on about passing both a single struct but also a slice of structs from C# to a CGO exported Go function, and also return them? Such as these examples:

type Person struct {
	Name             string
	Hobbies          []string
	FavouriteNumbers []int
	Age              int
	Single           bool
}

//export Struct
func Struct(person StructFromCSharpToGo) structFromGoToCSharp {

	// Use struct
	// return structToCSharp
}

//export StructSlice
func StructSlice(people StructSliceFromCSharpToGo) structSliceFromGoToCSharp  {

	// Use struct slice
	// return struct slice
}

func main() {}

Just get back if you need me to clearify anything, as I do see that I can get quite confusing in my examples and attempts to explain, because of my lack of knowledge in the topics.

Rust example

Hi,

It would be helpful if there was a Rust example.

I tried though wasn't able to get the linking flags to compile.

Cargo.toml

[package]
name = "client_rust"
version = "0.1.0"
authors = ["example"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
libc = "0.2"

src/main.rs

use libc::c_long;


#[link(name = "awesome", kind="dylib")]
extern {
    fn Add(num1: c_long, num2: c_long) -> ();
}

fn main() {
    unsafe { Add(5,5); }
    println!("Ran the unsafe code.");
}

EINVAL error from go runtime in dynamically linked case ?

Thanks for the examples.
I am playing a little bit with cgo at the moment and realized from your C examples that in the dynamically linked case (client1) the errno value is already set to EINVAL before even running the client code.
Whereas in the dynamically loaded case (client2), no error is set.

I have just run the two cases, and added printf("%s", strerror(errno)) at the very beginning of the main functions.

Am I missing something or is it that the initialization of the Go runtime may have left an error un-handled in the first case ?

Dart Example gives error with Dart 2.9.0-14.1.beta on MacOS

@dpurfield Thank you for giving Dart Example for FFI. But when I execute it, it gives the following errors.

Would really appreciate if you can help.

~ dart --version
Dart VM version: 2.9.0-14.1.beta (beta) (Tue Jun 9 10:52:57 2020 +0200) on "macos_x64"
$ dart client.dart 
client.dart:5:23: Error: Expected 0 type arguments.
class GoSlice extends Struct<GoSlice> {
                      ^
client.dart:35:24: Error: Expected 0 type arguments.
class GoString extends Struct<GoString> {
                       ^
client.dart:22:35: Error: Type argument 'GoSlice' doesn't conform to the bound 'NativeType' of the type variable 'T' on 'Pointer' in the return type.
 - 'GoSlice' is from 'client.dart'.
 - 'NativeType' is from 'dart:ffi'.
Try changing type arguments so that they conform to the bounds.
  static Pointer<GoSlice> fromList(List<int> units) {
                                  ^
client.dart:49:38: Error: Type argument 'GoString' doesn't conform to the bound 'NativeType' of the type variable 'T' on 'Pointer' in the return type.
 - 'GoString' is from 'client.dart'.
 - 'NativeType' is from 'dart:ffi'.
Try changing type arguments so that they conform to the bounds.
  static Pointer<GoString> fromString(String string) {
                                     ^
client.dart:17:35: Error: The method 'load' isn't defined for the class 'Pointer<Int64>'.
 - 'Pointer' is from 'dart:ffi'.
 - 'Int64' is from 'dart:ffi'.
Try correcting the name to the name of an existing method, or defining a method named 'load'.
      units.add(data.elementAt(i).load<int>());
                                  ^^^^
client.dart:23:32: Error: Method not found: 'Pointer.allocate'.
    final ptr = Pointer<Int64>.allocate(count: units.length);
                               ^^^^^^^^
client.dart:27:44: Error: Method not found: 'Pointer.allocate'.
    final GoSlice slice = Pointer<GoSlice>.allocate().load();
                                           ^^^^^^^^
client.dart:31:18: Error: The getter 'addressOf' isn't defined for the class 'GoSlice'.
 - 'GoSlice' is from 'client.dart'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'addressOf'.
    return slice.addressOf;
                 ^^^^^^^^^
client.dart:44:37: Error: The method 'load' isn't defined for the class 'Pointer<Uint8>'.
 - 'Pointer' is from 'dart:ffi'.
 - 'Uint8' is from 'dart:ffi'.
Try correcting the name to the name of an existing method, or defining a method named 'load'.
      units.add(string.elementAt(i).load<int>());
                                    ^^^^
client.dart:51:32: Error: Method not found: 'Pointer.allocate'.
    final ptr = Pointer<Uint8>.allocate(count: units.length);

Thanks,
Satinder

Image not found

⋊> ~/G/go-cshared-examples on master ⨯ go build -o awesome.so -buildmode=c-shared awesome.go                                                  14:23:25

⋊> ~/G/go-cshared-examples on master ⨯ ll                                                                                                     14:23:35
total 3984
-rw-r--r--   1 marcelaraujo  staff   2.4K Mar  8 14:16 Client.java
-rw-r--r--   1 marcelaraujo  staff   1.0K Mar  8 14:16 LICENSE
-rw-r--r--   1 marcelaraujo  staff    18K Mar  8 14:16 README.md
-rw-r--r--   1 marcelaraujo  staff   419B Mar  8 14:16 awesome.go
-rw-r--r--   1 marcelaraujo  staff   1.4K Mar  8 14:23 awesome.h
-rw-r--r--   1 marcelaraujo  staff   1.9M Mar  8 14:23 awesome.so

⋊> ~/G/go-cshared-examples on master ⨯ node client.js                                                                                         14:20:44
/Users/marcelaraujo/GoProjects/go-cshared-examples/node_modules/ffi/lib/dynamic_library.js:74
    throw new Error('Dynamic Linking Error: ' + err)
    ^

Error: Dynamic Linking Error: dlopen(./awesome.so.dylib, 2): image not found
    at new DynamicLibrary (/Users/marcelaraujo/GoProjects/go-cshared-examples/node_modules/ffi/lib/dynamic_library.js:74:11)
    at Object.Library (/Users/marcelaraujo/GoProjects/go-cshared-examples/node_modules/ffi/lib/library.js:45:12)
    at Object.<anonymous> (/Users/marcelaraujo/GoProjects/go-cshared-examples/client.js:25:19)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:425:7)

header file is not generated

main.go:
package main

//export add
func add(a, b int) int {
return a + b
}

func main() {}

command:
go build -o libgo.so -buildmode=c-shared main.go

there is no error but only libgo.so generated.

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.