go2hx

manual

github

Module: stdgo.encoding.hex

(view library index)

Overview

Package hex implements hexadecimal encoding and decoding.

Index

Examples

Constants

import stdgo.encoding.hex.Hex
final _bufferSize:stdgo.GoUInt64 = ((1024i64 : stdgo.GoUInt64))

bufferSize is the number of hexadecimal characters to buffer in encoder and decoder.

final _hextable:stdgo.GoString = (("0123456789abcdef" : stdgo.GoString))
final _reverseHexTable:stdgo.GoString = stdgo.Go.str(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, "\x07\x08\t", 255, 255, 255, 255, 255, 255, 255, "\n\x0B\x0C\r", 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, "\n\x0B\x0C\r", 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255)

Variables

import stdgo.encoding.hex.Hex
var _encDecTests:stdgo.Slice<stdgo.encoding.hex.T_encDecTest>
var _errTests:stdgo.Slice<stdgo.encoding.hex.T__struct_0>
var _expectedHexDump:stdgo.Slice<stdgo.GoUInt8>
var _sink:stdgo.Slice<stdgo.GoByte>
var errLength:stdgo.Error

ErrLength reports an attempt to decode an odd-length input using Decode or DecodeString. The stream-based Decoder returns io.ErrUnexpectedEOF instead of ErrLength.

Functions

import stdgo.encoding.hex.Hex

function _toChar

function _toChar(_b:stdgo.GoByte):stdgo.GoByte

(view code)

function benchmarkDecode

function benchmarkDecode(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkDump

function benchmarkDump(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkEncode

function benchmarkEncode(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function decode

function decode(_dst:stdgo.Slice<stdgo.GoByte>, _src:stdgo.Slice<stdgo.GoByte>):{
	_1:stdgo.Error;
	_0:stdgo.GoInt;
}

Decode decodes src into DecodedLen(len(src)) bytes, returning the actual number of bytes written to dst.

Decode expects that src contains only hexadecimal characters and that src has even length. If the input is malformed, Decode returns the number of bytes decoded before the error.

exampleDecode

function exampleDecode():Void {
        var _src = (("48656c6c6f20476f7068657221" : stdgo.GoString) : stdgo.Slice<stdgo.GoByte>);
        var _dst = new stdgo.Slice<stdgo.GoUInt8>((stdgo.encoding.hex.Hex.decodedLen((_src.length)) : stdgo.GoInt).toBasic(), 0).__setNumber32__();
        var __tmp__ = stdgo.encoding.hex.Hex.decode(_dst, _src), _n:stdgo.GoInt = __tmp__._0, _err:stdgo.Error = __tmp__._1;
        if (_err != null) {
            stdgo.log.Log.fatal(stdgo.Go.toInterface(_err));
        };
        stdgo.fmt.Fmt.printf(("%s\n" : stdgo.GoString), stdgo.Go.toInterface((_dst.__slice__(0, _n) : stdgo.Slice<stdgo.GoUInt8>)));
    }

(view code)

function decodeString

function decodeString(_s:stdgo.GoString):{
	_1:stdgo.Error;
	_0:stdgo.Slice<stdgo.GoByte>;
}

DecodeString returns the bytes represented by the hexadecimal string s.

DecodeString expects that src contains only hexadecimal characters and that src has even length. If the input is malformed, DecodeString returns the bytes decoded before the error.

exampleDecodeString

function exampleDecodeString():Void {
        {};
        var __tmp__ = stdgo.encoding.hex.Hex.decodeString(("48656c6c6f20476f7068657221" : stdgo.GoString)), _decoded:stdgo.Slice<stdgo.GoUInt8> = __tmp__._0, _err:stdgo.Error = __tmp__._1;
        if (_err != null) {
            stdgo.log.Log.fatal(stdgo.Go.toInterface(_err));
        };
        stdgo.fmt.Fmt.printf(("%s\n" : stdgo.GoString), stdgo.Go.toInterface(_decoded));
    }

(view code)

function decodedLen

function decodedLen(_x:stdgo.GoInt):stdgo.GoInt

DecodedLen returns the length of a decoding of x source bytes. Specifically, it returns x / 2.

(view code)

function dump

function dump(_data:stdgo.Slice<stdgo.GoByte>):stdgo.GoString

Dump returns a string that contains a hex dump of the given data. The format of the hex dump matches the output of \hexdump \-C\ on the command line.

exampleDump

function exampleDump():Void {
        var _content = (("Go is an open source programming language." : stdgo.GoString) : stdgo.Slice<stdgo.GoByte>);
        stdgo.fmt.Fmt.printf(("%s" : stdgo.GoString), stdgo.Go.toInterface(stdgo.encoding.hex.Hex.dump(_content)));
    }

(view code)

function dumper

function dumper(_w:stdgo.io.Writer):stdgo.io.WriteCloser

Dumper returns a WriteCloser that writes a hex dump of all written data to w. The format of the dump matches the output of \hexdump \-C\ on the command line.

exampleDumper

function exampleDumper():Void {
        var __deferstack__:Array<Void -> Void> = [];
        try {
            var _lines = (new stdgo.Slice<stdgo.GoString>(3, 3, ("Go is an open source programming language." : stdgo.GoString), ("\n" : stdgo.GoString), ("We encourage all Go users to subscribe to golang-announce." : stdgo.GoString)) : stdgo.Slice<stdgo.GoString>);
            var _stdoutDumper:stdgo.io.Io.WriteCloser = stdgo.encoding.hex.Hex.dumper(stdgo.Go.asInterface(stdgo.os.Os.stdout));
            __deferstack__.unshift(() -> _stdoutDumper.close());
            for (__0 => _line in _lines) {
                _stdoutDumper.write((_line : stdgo.Slice<stdgo.GoByte>));
            };
            {
                for (defer in __deferstack__) {
                    defer();
                };
                if (stdgo.Go.recover_exception != null) throw stdgo.Go.recover_exception;
                return;
            };
        } catch(__exception__) {
            var exe:Dynamic = __exception__.native;
            if ((exe is haxe.ValueException)) exe = exe.value;
            if (!(exe is stdgo.AnyInterface.AnyInterfaceData)) {
                exe = stdgo.Go.toInterface(__exception__.message);
            };
            stdgo.Go.recover_exception = exe;
            for (defer in __deferstack__) {
                defer();
            };
            if (stdgo.Go.recover_exception != null) throw stdgo.Go.recover_exception;
            return;
        };
    }

(view code)

function encode

function encode(_dst:stdgo.Slice<stdgo.GoByte>, _src:stdgo.Slice<stdgo.GoByte>):stdgo.GoInt

Encode encodes src into EncodedLen(len(src)) bytes of dst. As a convenience, it returns the number of bytes written to dst, but this value is always EncodedLen(len(src)). Encode implements hexadecimal encoding.

exampleEncode

function exampleEncode():Void {
        var _src = (("Hello Gopher!" : stdgo.GoString) : stdgo.Slice<stdgo.GoByte>);
        var _dst = new stdgo.Slice<stdgo.GoUInt8>((stdgo.encoding.hex.Hex.encodedLen((_src.length)) : stdgo.GoInt).toBasic(), 0).__setNumber32__();
        stdgo.encoding.hex.Hex.encode(_dst, _src);
        stdgo.fmt.Fmt.printf(("%s\n" : stdgo.GoString), stdgo.Go.toInterface(_dst));
    }

(view code)

function encodeToString

function encodeToString(_src:stdgo.Slice<stdgo.GoByte>):stdgo.GoString

EncodeToString returns the hexadecimal encoding of src.

exampleEncodeToString

function exampleEncodeToString():Void {
        var _src = (("Hello" : stdgo.GoString) : stdgo.Slice<stdgo.GoByte>);
        var _encodedStr:stdgo.GoString = stdgo.encoding.hex.Hex.encodeToString(_src)?.__copy__();
        stdgo.fmt.Fmt.printf(("%s\n" : stdgo.GoString), stdgo.Go.toInterface(_encodedStr));
    }

(view code)

function encodedLen

function encodedLen(_n:stdgo.GoInt):stdgo.GoInt

EncodedLen returns the length of an encoding of n source bytes. Specifically, it returns n * 2.

(view code)

function newDecoder

function newDecoder(_r:stdgo.io.Reader):stdgo.io.Reader

NewDecoder returns an io.Reader that decodes hexadecimal characters from r. NewDecoder expects that r contain only an even number of hexadecimal characters.

(view code)

function newEncoder

function newEncoder(_w:stdgo.io.Writer):stdgo.io.Writer

NewEncoder returns an io.Writer that writes lowercase hexadecimal characters to w.

(view code)

function testDecode

function testDecode(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testDecodeErr

function testDecodeErr(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testDecodeString

function testDecodeString(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testDecodeStringErr

function testDecodeStringErr(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testDecoderErr

function testDecoderErr(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testDump

function testDump(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testDumper

function testDumper(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testDumper_doubleclose

function testDumper_doubleclose(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testDumper_earlyclose

function testDumper_earlyclose(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testEncode

function testEncode(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testEncodeToString

function testEncodeToString(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testEncoderDecoder

function testEncoderDecoder(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

Typedefs

import stdgo.encoding.hex.*

typedef InvalidByteError

typedef InvalidByteError = stdgo.GoUInt8;

InvalidByteError values describe errors resulting from an invalid byte in a hex string.

typedef T__struct_0

typedef T__struct_0 = {
	_out:stdgo.GoString;
	_in:stdgo.GoString;
	_err:stdgo.Error;
};

typedef T__struct_1

typedef T__struct_1 = {
	{<reader> | stdgo.io.Reader | meta:{<m>}};
};

typedef T__struct_2

typedef T__struct_2 = {
	{<writer> | stdgo.io.Writer | meta:{<m>}};
};