1
1
mirror of https://github.com/wader/fq.git synced 2025-01-08 23:59:50 +03:00

decode: Nicer scalar template and add doc

This commit is contained in:
Mattias Wadman 2021-11-17 16:13:10 +01:00
parent 15b6d64b49
commit ede2e77975
44 changed files with 2270 additions and 923 deletions

View File

@ -156,4 +156,5 @@
"[plaintext]": {
"files.trimTrailingWhitespace": false,
},
"fracturedjsonvsc.MaxInlineLength": 160,
}

View File

@ -6,6 +6,8 @@ import (
"io/ioutil"
"log"
"os"
"strconv"
"strings"
"text/template"
)
@ -20,6 +22,17 @@ func toInt(v interface{}) int {
}
}
func toString(v interface{}) string {
switch v := v.(type) {
case string:
return v
case int:
return strconv.Itoa(v)
default:
return ""
}
}
func main() {
funcMap := template.FuncMap{
"xrange": func(args ...interface{}) (interface{}, error) {
@ -36,6 +49,17 @@ func main() {
return v, nil
},
"replace": func(args ...interface{}) (interface{}, error) {
if len(args) < 3 {
return nil, errors.New("need tmpl, old and new argument")
}
s := toString(args[0])
o := toString(args[1])
n := toString(args[2])
return strings.Replace(s, o, n, -1), nil
},
}
data := map[string]interface{}{}

View File

@ -53,7 +53,7 @@ func apev2Decode(d *decode.D, in interface{}) interface{} {
d.FieldU8("key_terminator")
if binaryItem {
d.LenFn(int64(itemSize)*8, func(d *decode.D) {
d.FieldUTF8NullTerminated("filename")
d.FieldUTF8Null("filename")
// assume image if binary
dv, _, _ := d.FieldTryFormat("value", imageFormat, nil)
if dv == nil {

View File

@ -59,7 +59,7 @@ func obuDecode(d *decode.D, in interface{}) interface{} {
d.FieldStruct("header", func(d *decode.D) {
d.FieldU1("forbidden_bit")
obuType = d.FieldU4("type", d.MapUToStr(obuTypeNames))
obuType = d.FieldU4("type", d.MapUToStrSym(obuTypeNames))
hasExtension = d.FieldBool("extension_flag")
hasSizeField = d.FieldBool("has_size_field")
d.FieldU1("reserved_1bit")

View File

@ -170,7 +170,7 @@ func fieldFormatRR(d *decode.D, count uint64, name string, structName string) {
for i := uint64(0); i < count; i++ {
d.FieldStruct(structName, func(d *decode.D) {
fieldFormatLabel(d, "name")
typ := d.FieldU16("type", d.MapUToStr(typeNames))
typ := d.FieldU16("type", d.MapUToStrSym(typeNames))
class := d.FieldU16("class", d.MapURangeToScalar(classNames))
d.FieldU32("ttl")
// TODO: pointer?
@ -194,11 +194,11 @@ func fieldFormatRR(d *decode.D, count uint64, name string, structName string) {
func dnsDecode(d *decode.D, in interface{}) interface{} {
d.FieldStruct("header", func(d *decode.D) {
d.FieldU16("id")
d.FieldBool("query", d.MapBoolToStr(decode.BoolToStr{
d.FieldBool("query", d.MapBoolToStrSym(decode.BoolToStr{
true: "Query",
false: "Response",
}))
d.FieldU4("opcode", d.MapUToStr(decode.UToStr{
d.FieldU4("opcode", d.MapUToStrSym(decode.UToStr{
0: "Query",
1: "IQuery",
2: "Status",
@ -222,7 +222,7 @@ func dnsDecode(d *decode.D, in interface{}) interface{} {
for i := uint64(0); i < qdCount; i++ {
d.FieldStruct("question", func(d *decode.D) {
fieldFormatLabel(d, "name")
d.FieldU16("type", d.MapUToStr(typeNames))
d.FieldU16("type", d.MapUToStrSym(typeNames))
d.FieldU16("class", d.MapURangeToScalar(classNames))
})
}

View File

@ -132,10 +132,10 @@ func elfDecode(d *decode.D, in interface{}) interface{} {
d.FieldStruct("ident", func(d *decode.D) {
d.FieldRawLen("magic", 4*8, d.AssertBitBuf([]byte("\x7fELF")))
archBits = int(d.FieldU8("class", d.MapUToU(classBits)))
endian = d.FieldU8("data", d.MapUToStr(endianNames))
archBits = int(d.FieldU8("class", d.MapUToUSym(classBits)))
endian = d.FieldU8("data", d.MapUToStrSym(endianNames))
d.FieldU8("version")
d.FieldU8("os_abi", d.MapUToStr(osABINames))
d.FieldU8("os_abi", d.MapUToStrSym(osABINames))
d.FieldU8("abi_version")
d.FieldRawLen("pad", 7*8, d.BitBufIsZero)
})
@ -151,7 +151,7 @@ func elfDecode(d *decode.D, in interface{}) interface{} {
// TODO: hex functions?
d.FieldU16("type", d.MapUToStr(decode.UToStr{
d.FieldU16("type", d.MapUToStrSym(decode.UToStr{
0x00: "None",
0x01: "Rel",
0x02: "Exec",
@ -163,7 +163,7 @@ func elfDecode(d *decode.D, in interface{}) interface{} {
0xffff: "Hiproc",
}), d.Hex)
d.FieldU16("machine", d.MapUToStr(decode.UToStr{
d.FieldU16("machine", d.MapUToStrSym(decode.UToStr{
0x00: "No specific instruction set",
0x01: "AT&T WE 32100",
0x02: "SPARC",
@ -291,7 +291,7 @@ func elfDecode(d *decode.D, in interface{}) interface{} {
switch archBits {
case 32:
d.FieldUFn("p_type", func(d *decode.D) uint64 { return d.U32() & 0xf }, d.MapUToStr(pTypeNames))
d.FieldUFn("p_type", func(d *decode.D) uint64 { return d.U32() & 0xf }, d.MapUToStrSym(pTypeNames))
offset = d.FieldU("p_offset", archBits)
d.FieldU("p_vaddr", archBits)
d.FieldU("p_paddr", archBits)
@ -300,7 +300,7 @@ func elfDecode(d *decode.D, in interface{}) interface{} {
pFlags(d)
d.FieldU32("p_align")
case 64:
d.FieldUFn("p_type", func(d *decode.D) uint64 { return d.U32() & 0xf }, d.MapUToStr(pTypeNames))
d.FieldUFn("p_type", func(d *decode.D) uint64 { return d.U32() & 0xf }, d.MapUToStrSym(pTypeNames))
pFlags(d)
offset = d.FieldU("p_offset", archBits)
d.FieldU("p_vaddr", archBits)
@ -447,7 +447,7 @@ func elfDecode(d *decode.D, in interface{}) interface{} {
switch archBits {
case 32:
shname = d.FieldScalar("sh_name", d.ScalarU32(), mapStrTable(strIndexTable)).SymStr()
typ = d.FieldU32("sh_type", d.MapUToStr(shTypeNames), d.Hex)
typ = d.FieldU32("sh_type", d.MapUToStrSym(shTypeNames), d.Hex)
shFlags(d, archBits)
d.FieldU("sh_addr", archBits)
offset = d.FieldU("sh_offset", archBits)
@ -458,7 +458,7 @@ func elfDecode(d *decode.D, in interface{}) interface{} {
d.FieldU32("sh_entsize")
case 64:
shname = d.FieldScalar("sh_name", d.ScalarU32(), mapStrTable(strIndexTable)).SymStr()
typ = d.FieldU32("sh_type", d.MapUToStr(shTypeNames), d.Hex)
typ = d.FieldU32("sh_type", d.MapUToStrSym(shTypeNames), d.Hex)
shFlags(d, archBits)
d.FieldU("sh_addr", archBits)
offset = d.FieldU("sh_offset", archBits)
@ -483,7 +483,7 @@ func elfDecode(d *decode.D, in interface{}) interface{} {
d.FieldArray("dynamic_tags", func(d *decode.D) {
for d.NotEnd() {
d.FieldStruct("tag", func(d *decode.D) {
tag := d.FieldUFn("tag", func(d *decode.D) uint64 { return d.U(archBits) }, d.MapUToStr(dtNames), d.Hex)
tag := d.FieldUFn("tag", func(d *decode.D) uint64 { return d.U(archBits) }, d.MapUToStrSym(dtNames), d.Hex)
switch tag {
case DT_NEEDED:
// TODO: DT_STRTAB

View File

@ -111,7 +111,7 @@ func frameDecode(d *decode.D, in interface{}) interface{} {
// <1> Blocking strategy:
// 0 : fixed-blocksize stream; frame header encodes the frame number
// 1 : variable-blocksize stream; frame header encodes the sample number
blockingStrategy := d.FieldU1("blocking_strategy", d.MapUToStr(BlockingStrategyNames))
blockingStrategy := d.FieldU1("blocking_strategy", d.MapUToStrSym(BlockingStrategyNames))
// <4> Block size in inter-channel samples:
// 0000 : reserved

View File

@ -53,7 +53,7 @@ func metadatablockDecode(d *decode.D, in interface{}) interface{} {
var streamInfo format.FlacStreamInfo
isLastBlock := d.FieldBool("last_block")
typ := d.FieldU7("type", d.MapUToStr(metadataBlockNames))
typ := d.FieldU7("type", d.MapUToStrSym(metadataBlockNames))
length := d.FieldU24("length")
switch typ {

View File

@ -48,7 +48,7 @@ func pictureDecode(d *decode.D, in interface{}) interface{} {
l := d.FieldU32(name + "_length")
return d.FieldUTF8(name, int(l))
}
d.FieldU32("picture_type", d.MapUToStr(pictureTypeNames))
d.FieldU32("picture_type", d.MapUToStrSym(pictureTypeNames))
lenStr("mime")
lenStr("description")
d.FieldU32("width")

View File

@ -90,7 +90,7 @@ func flvDecode(d *decode.D, in interface{}) interface{} {
}
fieldScriptDataValue := func(d *decode.D, _ string) uint64 {
typ := d.FieldU8("type", d.MapUToStr(typeNames))
typ := d.FieldU8("type", d.MapUToStrSym(typeNames))
if typ == typeECMAArray {
d.FieldU32("ecma_array_length")
}
@ -160,7 +160,7 @@ func flvDecode(d *decode.D, in interface{}) interface{} {
for !d.End() {
d.FieldStruct("tag", func(d *decode.D) {
d.FieldU32("previous_tag_size")
tagType := d.FieldU8("tag_type", d.MapUToStr(tagTypeNames))
tagType := d.FieldU8("tag_type", d.MapUToStrSym(tagTypeNames))
dataSize := d.FieldU24("data_size")
d.FieldU24("timestamp")
d.FieldU8("timestamp_extended")

View File

@ -77,7 +77,7 @@ func gifDecode(d *decode.D, in interface{}) interface{} {
case 0x21: /* "!" */
d.FieldStruct("extension_block", func(d *decode.D) {
d.FieldU8("introducer")
functionCode := d.FieldU8("function_code", d.MapUToStr(extensionNames), d.Hex)
functionCode := d.FieldU8("function_code", d.MapUToStrSym(extensionNames), d.Hex)
dataBytes := &bytes.Buffer{}

View File

@ -60,7 +60,7 @@ var deflateExtraFlagsNames = decode.UToStr{
func gzDecode(d *decode.D, in interface{}) interface{} {
d.FieldRawLen("identification", 2*8, d.AssertBitBuf([]byte("\x1f\x8b")))
compressionMethod := d.FieldU8("compression_method", d.MapUToStr(compressionMethodNames))
compressionMethod := d.FieldU8("compression_method", d.MapUToStrSym(compressionMethodNames))
hasHeaderCRC := false
hasExtra := false
hasName := false
@ -76,21 +76,21 @@ func gzDecode(d *decode.D, in interface{}) interface{} {
d.FieldU32LE("mtime") // TODO: unix time
switch compressionMethod {
case delfateMethod:
d.FieldU8("extra_flags", d.MapUToStr(deflateExtraFlagsNames))
d.FieldU8("extra_flags", d.MapUToStrSym(deflateExtraFlagsNames))
default:
d.FieldU8("extra_flags")
}
d.FieldU8("os", d.MapUToStr(osNames))
d.FieldU8("os", d.MapUToStrSym(osNames))
if hasExtra {
// TODO:
xLen := d.FieldU16("xlen")
d.FieldRawLen("extra_fields", int64(xLen*8))
}
if hasName {
d.FieldUTF8NullTerminated("name")
d.FieldUTF8Null("name")
}
if hasComment {
d.FieldUTF8NullTerminated("comment")
d.FieldUTF8Null("comment")
}
if hasHeaderCRC {
// TODO: validate

View File

@ -25,7 +25,7 @@ func xyzType(d *decode.D) {
}
func textType(d *decode.D) {
d.FieldUTF8NullTerminatedLen("text", int(d.BitsLeft()/8))
d.FieldUTF8NullFixedLen("text", int(d.BitsLeft()/8))
}
func paraType(d *decode.D) {
@ -37,13 +37,13 @@ func paraType(d *decode.D) {
func descType(d *decode.D) {
descLen := d.FieldU32("description_length")
d.FieldUTF8NullTerminatedLen("description", int(descLen))
d.FieldUTF8NullFixedLen("description", int(descLen))
d.FieldU32("language_code")
localDescLen := d.FieldU32("localizable_description_length")
d.FieldUTF8NullTerminatedLen("localizable_description", int(localDescLen))
d.FieldUTF8NullFixedLen("localizable_description", int(localDescLen))
d.FieldU16("script_code")
d.FieldU8("macintosh_description_length")
d.FieldUTF8NullTerminatedLen("macintosh_description", 67)
d.FieldUTF8NullFixedLen("macintosh_description", 67)
}
var typToDecode = map[string]func(d *decode.D){
@ -87,13 +87,13 @@ func iccProfileDecode(d *decode.D, in interface{}) interface{} {
d.LenFn(int64(size)*8, func(d *decode.D) {
d.FieldStruct("header", func(d *decode.D) {
d.FieldU32("size")
d.FieldUTF8NullTerminatedLen("cmm_type_signature", 4)
d.FieldUTF8NullFixedLen("cmm_type_signature", 4)
d.FieldUFn("version_major", decodeBCDU8)
d.FieldUFn("version_minor", decodeBCDU8)
d.FieldU16("version_reserved")
d.FieldUTF8NullTerminatedLen("device_class_signature", 4)
d.FieldUTF8NullTerminatedLen("color_space", 4)
d.FieldUTF8NullTerminatedLen("connection_space", 4)
d.FieldUTF8NullFixedLen("device_class_signature", 4)
d.FieldUTF8NullFixedLen("color_space", 4)
d.FieldUTF8NullFixedLen("connection_space", 4)
d.FieldStruct("timestamp", func(d *decode.D) {
d.FieldU16("year")
d.FieldU16("month")
@ -103,16 +103,16 @@ func iccProfileDecode(d *decode.D, in interface{}) interface{} {
d.FieldU16("seconds")
})
d.FieldUTF8NullTerminatedLen("file_signature", 4)
d.FieldUTF8NullTerminatedLen("primary_platform", 4)
d.FieldUTF8NullFixedLen("file_signature", 4)
d.FieldUTF8NullFixedLen("primary_platform", 4)
d.FieldU32("flags")
d.FieldUTF8NullTerminatedLen("device_manufacturer", 4)
d.FieldUTF8NullTerminatedLen("device_model", 4)
d.FieldUTF8NullTerminatedLen("device_attribute", 8)
d.FieldUTF8NullTerminatedLen("render_intent", 4)
d.FieldUTF8NullTerminatedLen("xyz_illuminant", 12)
d.FieldUTF8NullTerminatedLen("profile_creator_signature", 4)
d.FieldUTF8NullTerminatedLen("profile_id", 16)
d.FieldUTF8NullFixedLen("device_manufacturer", 4)
d.FieldUTF8NullFixedLen("device_model", 4)
d.FieldUTF8NullFixedLen("device_attribute", 8)
d.FieldUTF8NullFixedLen("render_intent", 4)
d.FieldUTF8NullFixedLen("xyz_illuminant", 12)
d.FieldUTF8NullFixedLen("profile_creator_signature", 4)
d.FieldUTF8NullFixedLen("profile_id", 16)
d.FieldRawLen("reserved", 28*8, d.BitBufIsZero)
})
@ -121,12 +121,12 @@ func iccProfileDecode(d *decode.D, in interface{}) interface{} {
d.FieldArray("table", func(d *decode.D) {
for i := uint64(0); i < tagCount; i++ {
d.FieldStruct("element", func(d *decode.D) {
d.FieldUTF8NullTerminatedLen("signature", 4)
d.FieldUTF8NullFixedLen("signature", 4)
offset := d.FieldU32("offset")
size := d.FieldU32("size")
d.RangeFn(int64(offset)*8, int64(size)*8, func(d *decode.D) {
typ := d.FieldUTF8NullTerminatedLen("type", 4)
typ := d.FieldUTF8NullFixedLen("type", 4)
d.FieldU32("reserved")
if fn, ok := typToDecode[typ]; ok {

View File

@ -23,13 +23,13 @@ func id3v1Decode(d *decode.D, in interface{}) interface{} {
if d.PeekBits(8) == uint64('+') {
d.Error("looks like id3v11")
}
d.FieldUTF8NullTerminatedLen("song_name", 30)
d.FieldUTF8NullTerminatedLen("artist", 30)
d.FieldUTF8NullTerminatedLen("album_name", 30)
d.FieldUTF8NullTerminatedLen("year", 4)
d.FieldUTF8NullTerminatedLen("comment", 30)
d.FieldUTF8NullFixedLen("song_name", 30)
d.FieldUTF8NullFixedLen("artist", 30)
d.FieldUTF8NullFixedLen("album_name", 30)
d.FieldUTF8NullFixedLen("year", 4)
d.FieldUTF8NullFixedLen("comment", 30)
// from https://en.wikipedia.org/wiki/List_of_ID3v1_Genres
d.FieldU8("genre", d.MapUToStr(decode.UToStr{
d.FieldU8("genre", d.MapUToStrSym(decode.UToStr{
0: "Blues",
1: "Classic Rock",
2: "Country",

View File

@ -20,7 +20,7 @@ func id3v11Decode(d *decode.D, in interface{}) interface{} {
d.FieldUTF8("title", 60)
d.FieldUTF8("artist", 60)
d.FieldUTF8("album", 60)
d.FieldU8("speed", d.MapUToStr(decode.UToStr{
d.FieldU8("speed", d.MapUToStrSym(decode.UToStr{
0: "unset",
1: "slow",
2: "medium",

View File

@ -423,7 +423,7 @@ func decodeFrame(d *decode.D, version int) uint64 {
// Description <text string according to encoding> $00 (00)
// Picture data <binary data>
"APIC": func(d *decode.D) {
encoding := d.FieldU8("text_encoding", d.MapUToStr(encodingNames))
encoding := d.FieldU8("text_encoding", d.MapUToStrSym(encodingNames))
d.FieldStrFn("mime_type", textNullFn(encodingUTF8))
d.FieldU8("picture_type") // TODO: table
d.FieldStrFn("description", textNullFn(int(encoding)))
@ -440,7 +440,7 @@ func decodeFrame(d *decode.D, version int) uint64 {
// Content description <text string according to encoding> $00 (00)
// Encapsulated object <binary data>
"GEOB": func(d *decode.D) {
encoding := d.FieldU8("text_encoding", d.MapUToStr(encodingNames))
encoding := d.FieldU8("text_encoding", d.MapUToStrSym(encodingNames))
d.FieldStrFn("mime_type", textNullFn(encodingUTF8))
d.FieldStrFn("filename", textNullFn(int(encoding)))
d.FieldStrFn("description", textNullFn(int(encoding)))
@ -476,7 +476,7 @@ func decodeFrame(d *decode.D, version int) uint64 {
// Short content descrip. <text string according to encoding> $00 (00)
// The actual text <full text string according to encoding>
"COMM": func(d *decode.D) {
encoding := d.FieldU8("text_encoding", d.MapUToStr(encodingNames))
encoding := d.FieldU8("text_encoding", d.MapUToStrSym(encodingNames))
d.FieldUTF8("language", 3)
d.FieldStrFn("description", textNullFn(int(encoding)))
d.FieldStrFn("value", textFn(int(encoding), int(d.BitsLeft()/8)))
@ -492,7 +492,7 @@ func decodeFrame(d *decode.D, version int) uint64 {
// Text encoding $xx
// Information <text string(s) according to encoding>
"T000": func(d *decode.D) {
encoding := d.FieldU8("text_encoding", d.MapUToStr(encodingNames))
encoding := d.FieldU8("text_encoding", d.MapUToStrSym(encodingNames))
d.FieldStrFn("text", textFn(int(encoding), int(d.BitsLeft()/8)))
},
// User defined... "TXX"
@ -506,7 +506,7 @@ func decodeFrame(d *decode.D, version int) uint64 {
// Description <text string according to encoding> $00 (00)
// Value <text string according to encoding>
"TXXX": func(d *decode.D) {
encoding := d.FieldU8("text_encoding", d.MapUToStr(encodingNames))
encoding := d.FieldU8("text_encoding", d.MapUToStrSym(encodingNames))
d.FieldStrFn("description", textNullFn(int(encoding)))
d.FieldStrFn("value", textFn(int(encoding), int(d.BitsLeft()/8)))
},

View File

@ -328,7 +328,7 @@ func jpegDecode(d *decode.D, in interface{}) interface{} {
switch signature {
case "8BIM":
// TODO: description?
d.FieldU16("block", d.MapUToStr(psImageResourceBlockNames))
d.FieldU16("block", d.MapUToScalar(psImageResourceBlockNames))
d.FieldRawLen("data", d.BitsLeft())
default:
}

View File

@ -3,98 +3,98 @@ package jpeg
import "github.com/wader/fq/pkg/decode"
// based on https://www.adobe.com/devnet-apps/photoshop/fileformatashtml
var psImageResourceBlockNames = decode.UToStr{
0x03E8: `Contains five 2-byte values: number of channels, rows, columns, depth, and mode`,
0x03E9: `Macintosh print manager print info record`,
0x03EA: `Macintosh page format information. No longer read by Photoshop. (Obsolete)`,
0x03EB: `Indexed color table`,
0x03ED: `ResolutionInfo structure. See Appendix A in Photoshop API Guide.pdf.`,
0x03EE: `Names of the alpha channels as a series of Pascal strings.`,
0x03EF: `(Obsolete) See ID 1077DisplayInfo structure. See Appendix A in Photoshop API Guide.pdf.`,
0x03F0: `The caption as a Pascal string.`,
0x03F1: `Border information. Contains a fixed number (2 bytes real, 2 bytes fraction) for the border width, and 2 bytes for border units (1 = inches, 2 = cm, 3 = points, 4 = picas, 5 = columns).`,
0x03F2: `Background color. See See Color structure.`,
0x03F3: `Print flags. A series of one-byte boolean values (see Page Setup dialog): labels, crop marks, color bars, registration marks, negative, flip, interpolate, caption, print flags.`,
0x03F4: `Grayscale and multichannel halftoning information`,
0x03F5: `Color halftoning information`,
0x03F6: `Duotone halftoning information`,
0x03F7: `Grayscale and multichannel transfer function`,
0x03F8: `Color transfer functions`,
0x03F9: `Duotone transfer functions`,
0x03FA: `Duotone image information`,
0x03FB: `Two bytes for the effective black and white values for the dot range`,
0x03FC: `(Obsolete)`,
0x03FD: `EPS options`,
0x03FE: `Quick Mask information. 2 bytes containing Quick Mask channel ID; 1- byte boolean indicating whether the mask was initially empty.`,
0x03FF: `(Obsolete)`,
0x0400: `Layer state information. 2 bytes containing the index of target layer (0 = bottom layer).`,
0x0401: `Working path (not saved). See See Path resource format.`,
0x0402: `Layers group information. 2 bytes per layer containing a group ID for the dragging groups. Layers in a group have the same group ID.`,
0x0403: `(Obsolete)`,
0x0404: `IPTC-NAA record. Contains the File Info... information. See the documentation in the IPTC folder of the Documentation folder.`,
0x0405: `Image mode for raw format files`,
0x0406: `JPEG quality. Private.`,
0x0408: `(Photoshop 4.0) Grid and guides information. See See Grid and guides resource format.`,
0x0409: `(Photoshop 4.0) Thumbnail resource for Photoshop 4.0 only. See See Thumbnail resource format.`,
0x040A: `(Photoshop 4.0) Copyright flag. Boolean indicating whether image is copyrighted. Can be set via Property suite or by user in File Info...`,
0x040B: `(Photoshop 4.0) URL. Handle of a text string with uniform resource locator. Can be set via Property suite or by user in File Info...`,
0x040C: `(Photoshop 5.0) Thumbnail resource (supersedes resource 1033). See See Thumbnail resource format.`,
0x040D: `(Photoshop 5.0) Global Angle. 4 bytes that contain an integer between 0 and 359, which is the global lighting angle for effects layer. If not present, assumed to be 30.`,
0x040E: `(Obsolete) See ID 1073 below. (Photoshop 5.0) Color samplers resource. See See Color samplers resource format.`,
0x040F: `(Photoshop 5.0) ICC Profile. The raw bytes of an ICC (International Color Consortium) format profile. See ICC1v42_2006-05.pdf in the Documentation folder and icProfileHeader.h in Sample Code\Common\Includes .`,
0x0410: `(Photoshop 5.0) Watermark. One byte.`,
0x0411: `(Photoshop 5.0) ICC Untagged Profile. 1 byte that disables any assumed profile handling when opening the file. 1 = intentionally untagged.`,
0x0412: `(Photoshop 5.0) Effects visible. 1-byte global flag to show/hide all the effects layer. Only present when they are hidden.`,
0x0413: `(Photoshop 5.0) Spot Halftone. 4 bytes for version, 4 bytes for length, and the variable length data.`,
0x0414: `(Photoshop 5.0) Document-specific IDs seed number. 4 bytes: Base value, starting at which layer IDs will be generated (or a greater value if existing IDs already exceed it). Its purpose is to avoid the case where we add layers, flatten, save, open, and then add more layers that end up with the same IDs as the first set.`,
0x0415: `(Photoshop 5.0) Unicode Alpha Names. Unicode string`,
0x0416: `(Photoshop 6.0) Indexed Color Table Count. 2 bytes for the number of colors in table that are actually defined`,
0x0417: `(Photoshop 6.0) Transparency Index. 2 bytes for the index of transparent color, if any.`,
0x0419: `(Photoshop 6.0) Global Altitude. 4 byte entry for altitude`,
0x041A: `(Photoshop 6.0) Slices. See See Slices resource format.`,
0x041B: `(Photoshop 6.0) Workflow URL. Unicode string`,
0x041C: `(Photoshop 6.0) Jump To XPEP. 2 bytes major version, 2 bytes minor version, 4 bytes count. Following is repeated for count: 4 bytes block size, 4 bytes key, if key = 'jtDd' , then next is a Boolean for the dirty flag; otherwise it's a 4 byte entry for the mod date.`,
0x041D: `(Photoshop 6.0) Alpha Identifiers. 4 bytes of length, followed by 4 bytes each for every alpha identifier.`,
0x041E: `(Photoshop 6.0) URL List. 4 byte count of URLs, followed by 4 byte long, 4 byte ID, and Unicode string for each count.`,
0x0421: `(Photoshop 6.0) Version Info. 4 bytes version, 1 byte hasRealMergedData , Unicode string: writer name, Unicode string: reader name, 4 bytes file version.`,
0x0422: `(Photoshop 7.0) EXIF data 1. See http://www.kodak.com/global/plugins/acrobat/en/service/digCam/exifStandard2.pdf`,
0x0423: `(Photoshop 7.0) EXIF data 3. See http://www.kodak.com/global/plugins/acrobat/en/service/digCam/exifStandard2.pdf`,
0x0424: `(Photoshop 7.0) XMP metadata. File info as XML description. See http://www.adobe.com/devnet/xmp/`,
0x0425: `(Photoshop 7.0) Caption digest. 16 bytes: RSA Data Security, MD5 message-digest algorithm`,
0x0426: `(Photoshop 7.0) Print scale. 2 bytes style (0 = centered, 1 = size to fit, 2 = user defined). 4 bytes x location (floating point). 4 bytes y location (floating point). 4 bytes scale (floating point)`,
0x0428: `(Photoshop CS) Pixel Aspect Ratio. 4 bytes (version = 1 or 2), 8 bytes double, x / y of a pixel. Version 2, attempting to correct values for NTSC and PAL, previously off by a factor of approx. 5%.`,
0x0429: `(Photoshop CS) Layer Comps. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure)`,
0x042A: `(Photoshop CS) Alternate Duotone Colors. 2 bytes (version = 1), 2 bytes count, following is repeated for each count: [ Color: 2 bytes for space followed by 4 * 2 byte color component ], following this is another 2 byte count, usually 256, followed by Lab colors one byte each for L, a, b. This resource is not read or used by Photoshop.`,
0x042B: `(Photoshop CS)Alternate Spot Colors. 2 bytes (version = 1), 2 bytes channel count, following is repeated for each count: 4 bytes channel ID, Color: 2 bytes for space followed by 4 * 2 byte color component. This resource is not read or used by Photoshop.`,
0x042D: `(Photoshop CS2) Layer Selection ID(s). 2 bytes count, following is repeated for each count: 4 bytes layer ID`,
0x042E: `(Photoshop CS2) HDR Toning information`,
0x042F: `(Photoshop CS2) Print info`,
0x0430: `(Photoshop CS2) Layer Group(s) Enabled ID. 1 byte for each layer in the document, repeated by length of the resource. NOTE: Layer groups have start and end markers`,
0x0431: `(Photoshop CS3) Color samplers resource. Also see ID 1038 for old format. See See Color samplers resource format.`,
0x0432: `(Photoshop CS3) Measurement Scale. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure)`,
0x0433: `(Photoshop CS3) Timeline Information. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure)`,
0x0434: `(Photoshop CS3) Sheet Disclosure. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure)`,
0x0435: `(Photoshop CS3) DisplayInfo structure to support floating point clors. Also see ID 1007. See Appendix A in Photoshop API Guide.pdf .`,
0x0436: `(Photoshop CS3) Onion Skins. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure)`,
0x0438: `(Photoshop CS4) Count Information. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure) Information about the count in the document. See the Count Tool.`,
0x043A: `(Photoshop CS5) Print Information. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure) Information about the current print settings in the document. The color management options.`,
0x043B: `(Photoshop CS5) Print Style. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure) Information about the current print style in the document. The printing marks, labels, ornaments, etc.`,
0x043C: `(Photoshop CS5) Macintosh NSPrintInfo. Variable OS specific info for Macintosh. NSPrintInfo. It is recommended that you do not interpret or use this data.`,
0x043D: `(Photoshop CS5) Windows DEVMODE. Variable OS specific info for Windows. DEVMODE. It is recommended that you do not interpret or use this data.`,
0x043E: `(Photoshop CS6) Auto Save File Path. Unicode string. It is recommended that you do not interpret or use this data.`,
0x043F: `(Photoshop CS6) Auto Save Format. Unicode string. It is recommended that you do not interpret or use this data.`,
0x0440: `(Photoshop CC) Path Selection State. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure) Information about the current path selection state.`,
// 0x07D0 - 0x0BB6: `Path Information (saved paths). See See Path resource format.`,
0x0BB7: `Name of clipping path. See See Path resource format.`,
0x0BB8: `(Photoshop CC) Origin Path Info. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure) Information about the origin path data.`,
// 0x0FA0 - 0x1387: `Plug-In resource(s). Resources added by a plug-in. See the plug-in API found in the SDK documentation`,
0x1B58: `Image Ready variables. XML representation of variables definition`,
0x1B59: `Image Ready data sets`,
0x1B5A: `Image Ready default selected state`,
0x1B5B: `Image Ready 7 rollover expanded state`,
0x1B5C: `Image Ready rollover expanded state`,
0x1B5D: `Image Ready save layer settings`,
0x1B5E: `Image Ready version`,
0x1F40: `(Photoshop CS3) Lightroom workflow, if present the document is in the middle of a Lightroom workflow.`,
0x2710: `Print flags information. 2 bytes version ( = 1), 1 byte center crop marks, 1 byte ( = 0), 4 bytes bleed width value, 2 bytes bleed width scale.`,
var psImageResourceBlockNames = decode.UToScalar{
0x03E8: {Description: `Contains five 2-byte values: number of channels, rows, columns, depth, and mode`},
0x03E9: {Description: `Macintosh print manager print info record`},
0x03EA: {Description: `Macintosh page format information. No longer read by Photoshop. (Obsolete)`},
0x03EB: {Description: `Indexed color table`},
0x03ED: {Description: `ResolutionInfo structure. See Appendix A in Photoshop API Guide.pdf.`},
0x03EE: {Description: `Names of the alpha channels as a series of Pascal strings.`},
0x03EF: {Description: `(Obsolete) See ID 1077DisplayInfo structure. See Appendix A in Photoshop API Guide.pdf.`},
0x03F0: {Description: `The caption as a Pascal string.`},
0x03F1: {Description: `Border information. Contains a fixed number (2 bytes real, 2 bytes fraction) for the border width, and 2 bytes for border units (1 = inches, 2 = cm, 3 = points, 4 = picas, 5 = columns).`},
0x03F2: {Description: `Background color. See See Color structure.`},
0x03F3: {Description: `Print flags. A series of one-byte boolean values (see Page Setup dialog): labels, crop marks, color bars, registration marks, negative, flip, interpolate, caption, print flags.`},
0x03F4: {Description: `Grayscale and multichannel halftoning information`},
0x03F5: {Description: `Color halftoning information`},
0x03F6: {Description: `Duotone halftoning information`},
0x03F7: {Description: `Grayscale and multichannel transfer function`},
0x03F8: {Description: `Color transfer functions`},
0x03F9: {Description: `Duotone transfer functions`},
0x03FA: {Description: `Duotone image information`},
0x03FB: {Description: `Two bytes for the effective black and white values for the dot range`},
0x03FC: {Description: `(Obsolete)`},
0x03FD: {Description: `EPS options`},
0x03FE: {Description: `Quick Mask information. 2 bytes containing Quick Mask channel ID; 1- byte boolean indicating whether the mask was initially empty.`},
0x03FF: {Description: `(Obsolete)`},
0x0400: {Description: `Layer state information. 2 bytes containing the index of target layer (0 = bottom layer).`},
0x0401: {Description: `Working path (not saved). See See Path resource format.`},
0x0402: {Description: `Layers group information. 2 bytes per layer containing a group ID for the dragging groups. Layers in a group have the same group ID.`},
0x0403: {Description: `(Obsolete)`},
0x0404: {Description: `IPTC-NAA record. Contains the File Info... information. See the documentation in the IPTC folder of the Documentation folder.`},
0x0405: {Description: `Image mode for raw format files`},
0x0406: {Description: `JPEG quality. Private.`},
0x0408: {Description: `(Photoshop 4.0) Grid and guides information. See See Grid and guides resource format.`},
0x0409: {Description: `(Photoshop 4.0) Thumbnail resource for Photoshop 4.0 only. See See Thumbnail resource format.`},
0x040A: {Description: `(Photoshop 4.0) Copyright flag. Boolean indicating whether image is copyrighted. Can be set via Property suite or by user in File Info...`},
0x040B: {Description: `(Photoshop 4.0) URL. Handle of a text string with uniform resource locator. Can be set via Property suite or by user in File Info...`},
0x040C: {Description: `(Photoshop 5.0) Thumbnail resource (supersedes resource 1033). See See Thumbnail resource format.`},
0x040D: {Description: `(Photoshop 5.0) Global Angle. 4 bytes that contain an integer between 0 and 359, which is the global lighting angle for effects layer. If not present, assumed to be 30.`},
0x040E: {Description: `(Obsolete) See ID 1073 below. (Photoshop 5.0) Color samplers resource. See See Color samplers resource format.`},
0x040F: {Description: `(Photoshop 5.0) ICC Profile. The raw bytes of an ICC (International Color Consortium) format profile. See ICC1v42_2006-05.pdf in the Documentation folder and icProfileHeader.h in Sample Code\Common\Includes .`},
0x0410: {Description: `(Photoshop 5.0) Watermark. One byte.`},
0x0411: {Description: `(Photoshop 5.0) ICC Untagged Profile. 1 byte that disables any assumed profile handling when opening the file. 1 = intentionally untagged.`},
0x0412: {Description: `(Photoshop 5.0) Effects visible. 1-byte global flag to show/hide all the effects layer. Only present when they are hidden.`},
0x0413: {Description: `(Photoshop 5.0) Spot Halftone. 4 bytes for version, 4 bytes for length, and the variable length data.`},
0x0414: {Description: `(Photoshop 5.0) Document-specific IDs seed number. 4 bytes: Base value, starting at which layer IDs will be generated (or a greater value if existing IDs already exceed it). Its purpose is to avoid the case where we add layers, flatten, save, open, and then add more layers that end up with the same IDs as the first set.`},
0x0415: {Description: `(Photoshop 5.0) Unicode Alpha Names. Unicode string`},
0x0416: {Description: `(Photoshop 6.0) Indexed Color Table Count. 2 bytes for the number of colors in table that are actually defined`},
0x0417: {Description: `(Photoshop 6.0) Transparency Index. 2 bytes for the index of transparent color, if any.`},
0x0419: {Description: `(Photoshop 6.0) Global Altitude. 4 byte entry for altitude`},
0x041A: {Description: `(Photoshop 6.0) Slices. See See Slices resource format.`},
0x041B: {Description: `(Photoshop 6.0) Workflow URL. Unicode string`},
0x041C: {Description: `(Photoshop 6.0) Jump To XPEP. 2 bytes major version, 2 bytes minor version, 4 bytes count. Following is repeated for count: 4 bytes block size, 4 bytes key, if key = 'jtDd' , then next is a Boolean for the dirty flag; otherwise it's a 4 byte entry for the mod date.`},
0x041D: {Description: `(Photoshop 6.0) Alpha Identifiers. 4 bytes of length, followed by 4 bytes each for every alpha identifier.`},
0x041E: {Description: `(Photoshop 6.0) URL List. 4 byte count of URLs, followed by 4 byte long, 4 byte ID, and Unicode string for each count.`},
0x0421: {Description: `(Photoshop 6.0) Version Info. 4 bytes version, 1 byte hasRealMergedData , Unicode string: writer name, Unicode string: reader name, 4 bytes file version.`},
0x0422: {Description: `(Photoshop 7.0) EXIF data 1. See http://www.kodak.com/global/plugins/acrobat/en/service/digCam/exifStandard2.pdf`},
0x0423: {Description: `(Photoshop 7.0) EXIF data 3. See http://www.kodak.com/global/plugins/acrobat/en/service/digCam/exifStandard2.pdf`},
0x0424: {Description: `(Photoshop 7.0) XMP metadata. File info as XML description. See http://www.adobe.com/devnet/xmp/`},
0x0425: {Description: `(Photoshop 7.0) Caption digest. 16 bytes: RSA Data Security, MD5 message-digest algorithm`},
0x0426: {Description: `(Photoshop 7.0) Print scale. 2 bytes style (0 = centered, 1 = size to fit, 2 = user defined). 4 bytes x location (floating point). 4 bytes y location (floating point). 4 bytes scale (floating point)`},
0x0428: {Description: `(Photoshop CS) Pixel Aspect Ratio. 4 bytes (version = 1 or 2), 8 bytes double, x / y of a pixel. Version 2, attempting to correct values for NTSC and PAL, previously off by a factor of approx. 5%.`},
0x0429: {Description: `(Photoshop CS) Layer Comps. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure)`},
0x042A: {Description: `(Photoshop CS) Alternate Duotone Colors. 2 bytes (version = 1), 2 bytes count, following is repeated for each count: [ Color: 2 bytes for space followed by 4 * 2 byte color component ], following this is another 2 byte count, usually 256, followed by Lab colors one byte each for L, a, b. This resource is not read or used by Photoshop.`},
0x042B: {Description: `(Photoshop CS)Alternate Spot Colors. 2 bytes (version = 1), 2 bytes channel count, following is repeated for each count: 4 bytes channel ID, Color: 2 bytes for space followed by 4 * 2 byte color component. This resource is not read or used by Photoshop.`},
0x042D: {Description: `(Photoshop CS2) Layer Selection ID(s). 2 bytes count, following is repeated for each count: 4 bytes layer ID`},
0x042E: {Description: `(Photoshop CS2) HDR Toning information`},
0x042F: {Description: `(Photoshop CS2) Print info`},
0x0430: {Description: `(Photoshop CS2) Layer Group(s) Enabled ID. 1 byte for each layer in the document, repeated by length of the resource. NOTE: Layer groups have start and end markers`},
0x0431: {Description: `(Photoshop CS3) Color samplers resource. Also see ID 1038 for old format. See See Color samplers resource format.`},
0x0432: {Description: `(Photoshop CS3) Measurement Scale. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure)`},
0x0433: {Description: `(Photoshop CS3) Timeline Information. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure)`},
0x0434: {Description: `(Photoshop CS3) Sheet Disclosure. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure)`},
0x0435: {Description: `(Photoshop CS3) DisplayInfo structure to support floating point clors. Also see ID 1007. See Appendix A in Photoshop API Guide.pdf .`},
0x0436: {Description: `(Photoshop CS3) Onion Skins. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure)`},
0x0438: {Description: `(Photoshop CS4) Count Information. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure) Information about the count in the document. See the Count Tool.`},
0x043A: {Description: `(Photoshop CS5) Print Information. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure) Information about the current print settings in the document. The color management options.`},
0x043B: {Description: `(Photoshop CS5) Print Style. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure) Information about the current print style in the document. The printing marks, labels, ornaments, etc.`},
0x043C: {Description: `(Photoshop CS5) Macintosh NSPrintInfo. Variable OS specific info for Macintosh. NSPrintInfo. It is recommended that you do not interpret or use this data.`},
0x043D: {Description: `(Photoshop CS5) Windows DEVMODE. Variable OS specific info for Windows. DEVMODE. It is recommended that you do not interpret or use this data.`},
0x043E: {Description: `(Photoshop CS6) Auto Save File Path. Unicode string. It is recommended that you do not interpret or use this data.`},
0x043F: {Description: `(Photoshop CS6) Auto Save Format. Unicode string. It is recommended that you do not interpret or use this data.`},
0x0440: {Description: `(Photoshop CC) Path Selection State. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure) Information about the current path selection state.`},
// 0x07D0 - 0x0BB6: `Path Information (saved paths). See See Path resource format.`},
0x0BB7: {Description: `Name of clipping path. See See Path resource format.`},
0x0BB8: {Description: `(Photoshop CC) Origin Path Info. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure) Information about the origin path data.`},
// 0x0FA0 - 0x1387: `Plug-In resource(s). Resources added by a plug-in. See the plug-in API found in the SDK documentation`},
0x1B58: {Description: `Image Ready variables. XML representation of variables definition`},
0x1B59: {Description: `Image Ready data sets`},
0x1B5A: {Description: `Image Ready default selected state`},
0x1B5B: {Description: `Image Ready 7 rollover expanded state`},
0x1B5C: {Description: `Image Ready rollover expanded state`},
0x1B5D: {Description: `Image Ready save layer settings`},
0x1B5E: {Description: `Image Ready version`},
0x1F40: {Description: `(Photoshop CS3) Lightroom workflow, if present the document is in the middle of a Lightroom workflow.`},
0x2710: {Description: `Print flags information. 2 bytes version ( = 1), 1 byte center crop marks, 1 byte ( = 0), 4 bytes bleed width value, 2 bytes bleed width scale.`},
}

View File

@ -229,7 +229,7 @@ func decodeMaster(d *decode.D, bitsLimit int64, tag ebml.Tag, dc *decodeContext)
dc.currentTrack.codec = v
}
case ebml.UTF8:
d.FieldUTF8NullTerminatedLen("value", int(tagSize))
d.FieldUTF8NullFixedLen("value", int(tagSize))
case ebml.Date:
// TODO:
/*

View File

@ -282,12 +282,12 @@ func init() {
"hdlr": func(ctx *decodeContext, d *decode.D) {
d.FieldU8("version")
d.FieldU24("flags")
d.FieldUTF8NullTerminatedLen("component_type", 4)
d.FieldUTF8NullFixedLen("component_type", 4)
subType := d.FieldUTF8("component_subtype", 4, d.MapStrToScalar(subTypeNames), d.TrimSpace)
d.FieldUTF8NullTerminatedLen("component_manufacturer", 4)
d.FieldUTF8NullFixedLen("component_manufacturer", 4)
d.FieldU32("component_flags")
d.FieldU32("component_flags_mask")
d.FieldUTF8NullTerminatedLen("component_name", int(d.BitsLeft()/8))
d.FieldUTF8NullFixedLen("component_name", int(d.BitsLeft()/8))
if ctx.currentTrack != nil {
// component_type seems to be all zero sometimes so can't look for "mhlr"
@ -406,7 +406,7 @@ func init() {
d.FieldFP32("vertical_resolution")
d.FieldU32("data_size")
d.FieldU16("frame_count")
d.FieldUTF8ShortString("compressor_name", 32)
d.FieldUTF8ShortStringFixedLen("compressor_name", 32)
d.FieldU16("depth")
d.FieldS16("color_table_id")
// TODO: if 0 decode ctab
@ -579,9 +579,9 @@ func init() {
1: "yes",
2: "no",
}
d.FieldU2("sample_depends_on", d.MapUToStr(values))
d.FieldU2("sample_is_depended_on", d.MapUToStr(values))
d.FieldU2("sample_has_redundancy", d.MapUToStr(values))
d.FieldU2("sample_depends_on", d.MapUToStrSym(values))
d.FieldU2("sample_is_depended_on", d.MapUToStrSym(values))
d.FieldU2("sample_has_redundancy", d.MapUToStrSym(values))
})
}
})
@ -896,13 +896,13 @@ func init() {
d.FieldU24("flags")
d.FieldU16("id")
d.FieldU16("protection_index")
d.FieldUTF8NullTerminated("item_name")
d.FieldUTF8Null("item_name")
// TODO: really optional? seems so
if d.NotEnd() {
d.FieldUTF8NullTerminated("content_type")
d.FieldUTF8Null("content_type")
}
if d.NotEnd() {
d.FieldUTF8NullTerminated("content_encoding")
d.FieldUTF8Null("content_encoding")
}
},
"iinf": func(ctx *decodeContext, d *decode.D) {

View File

@ -31,7 +31,7 @@ func playreadyPsshDecode(d *decode.D, in interface{}) interface{} {
count := d.FieldU16("count")
i := uint64(0)
d.FieldStructArrayLoop("records", "record", func() bool { return i < count }, func(d *decode.D) {
recordType := d.FieldU16("type", d.MapUToStr(recordTypeNames))
recordType := d.FieldU16("type", d.MapUToStrSym(recordTypeNames))
recordLen := d.FieldU16("len")
switch recordType {
case recordTypeRightsManagementHeader, recordTypeLicenseStore:

View File

@ -99,7 +99,7 @@ func aacLTPData(d *decode.D, objectType int, windowSequence int) {
func aacICSInfo(d *decode.D, objectType int) {
d.FieldU1("ics_reserved_bit")
windowSequence := d.FieldU2("window_sequence", d.MapUToStr(windowSequenceNames))
windowSequence := d.FieldU2("window_sequence", d.MapUToStrSym(windowSequenceNames))
d.FieldU1("window_shape")
switch windowSequence {
case EIGHT_SHORT_SEQUENCE:
@ -254,7 +254,7 @@ func aacFillElement(d *decode.D) {
d.FieldStruct("extension_payload", func(d *decode.D) {
d.LenFn(int64(cnt)*8, func(d *decode.D) {
extensionType := d.FieldU4("extension_type", d.MapUToStr(extensionPayloadIDNames))
extensionType := d.FieldU4("extension_type", d.MapUToStrSym(extensionPayloadIDNames))
// d.FieldU("align4", 2)
@ -279,7 +279,7 @@ func aacDecode(d *decode.D, in interface{}) interface{} {
seenTerm := false
for !seenTerm {
d.FieldStruct("element", func(d *decode.D) {
se := d.FieldU3("syntax_element", d.MapUToStr(syntaxElementNames))
se := d.FieldU3("syntax_element", d.MapUToStrSym(syntaxElementNames))
switch se {
case FIL:

View File

@ -65,12 +65,12 @@ func adtsFrameDecoder(d *decode.D, in interface{}) interface{} {
// Q 16 CRC if protection absent is 0
d.FieldU12("syncword", d.AssertU(0b1111_1111_1111), d.Bin)
d.FieldU1("mpeg_version", d.MapUToStr(decode.UToStr{0: "MPEG-4", 1: "MPEG2- AAC"}))
d.FieldU1("mpeg_version", d.MapUToStrSym(decode.UToStr{0: "MPEG-4", 1: "MPEG2- AAC"}))
d.FieldU2("layer", d.AssertU(0))
protectionAbsent := d.FieldBool("protection_absent", d.MapBoolToScalar(protectionAbsentNames))
// TODO: better sym names
objectType := d.FieldUFn("profile", func(d *decode.D) uint64 { return d.U2() + 1 }, d.MapUToStr(format.MPEGAudioObjectTypeNames))
objectType := d.FieldUFn("profile", func(d *decode.D) uint64 { return d.U2() + 1 }, d.MapUToStrSym(format.MPEGAudioObjectTypeNames))
d.FieldUScalarFn("sampling_frequency", func(d *decode.D) decode.Scalar {
v := d.U4()
if v == 15 {
@ -82,7 +82,7 @@ func adtsFrameDecoder(d *decode.D, in interface{}) interface{} {
return decode.Scalar{Description: "invalid"}
})
d.FieldU1("private_bit")
d.FieldU3("channel_configuration", d.MapUToStr(channelConfigurationNames))
d.FieldU3("channel_configuration", d.MapUToStrSym(channelConfigurationNames))
d.FieldU1("originality")
d.FieldU1("home")
d.FieldU1("copyrighted")

View File

@ -117,9 +117,9 @@ func avcDcrParameterSet(d *decode.D, numParamSets uint64) {
func avcDcrDecode(d *decode.D, in interface{}) interface{} {
d.FieldU8("configuration_version")
d.FieldU8("profile_indication", d.MapUToStr(avcProfileNames))
d.FieldU8("profile_indication", d.MapUToStrSym(avcProfileNames))
d.FieldU8("profile_compatibility")
d.FieldU8("level_indication", d.MapUToStr(avcLevelNames))
d.FieldU8("level_indication", d.MapUToStrSym(avcLevelNames))
d.FieldU6("reserved0")
lengthSizeMinusOne := d.FieldU2("length_size_minus_one")
d.FieldU3("reserved1")

View File

@ -112,7 +112,7 @@ func avcNALUDecode(d *decode.D, in interface{}) interface{} {
avcNALCodedSliceExtension:
d.FieldStruct("slice_header", func(d *decode.D) {
d.FieldUFn("first_mb_in_slice", uEV)
d.FieldUFn("slice_type", uEV, d.MapUToStr(sliceNames))
d.FieldUFn("slice_type", uEV, d.MapUToStrSym(sliceNames))
d.FieldUFn("pic_parameter_set_id", uEV)
// TODO: if ( separate_colour_plane_flag from SPS ) colour_plane_id; frame_num
})

View File

@ -101,7 +101,7 @@ func ffSum(d *decode.D) uint64 {
}
func avcSEIDecode(d *decode.D, in interface{}) interface{} {
payloadType := d.FieldUFn("payload_type", func(d *decode.D) uint64 { return ffSum(d) }, d.MapUToStr(seiNames))
payloadType := d.FieldUFn("payload_type", func(d *decode.D) uint64 { return ffSum(d) }, d.MapUToStrSym(seiNames))
payloadSize := d.FieldUFn("payload_size", func(d *decode.D) uint64 { return ffSum(d) })
d.LenFn(int64(payloadSize)*8, func(d *decode.D) {

View File

@ -97,7 +97,7 @@ func avcHdrParameters(d *decode.D) {
}
func avcSPSDecode(d *decode.D, in interface{}) interface{} {
profileIdc := d.FieldU8("profile_idc", d.MapUToStr(avcProfileNames))
profileIdc := d.FieldU8("profile_idc", d.MapUToStrSym(avcProfileNames))
d.FieldBool("constraint_set0_flag")
d.FieldBool("constraint_set1_flag")
d.FieldBool("constraint_set2_flag")
@ -105,7 +105,7 @@ func avcSPSDecode(d *decode.D, in interface{}) interface{} {
d.FieldBool("constraint_set4_flag")
d.FieldBool("constraint_set5_flag")
d.FieldU2("reserved_zero_2bits")
d.FieldU8("level_idc", d.MapUToStr(avcLevelNames))
d.FieldU8("level_idc", d.MapUToStrSym(avcLevelNames))
d.FieldUFn("seq_parameter_set_id", uEV)
switch profileIdc {

View File

@ -48,7 +48,7 @@ func hevcDcrDecode(d *decode.D, in interface{}) interface{} {
d.FieldStruct("array", func(d *decode.D) {
d.FieldU1("array_completeness")
d.FieldU1("reserved0")
d.FieldU6("nal_unit_type", d.MapUToStr(hevcNALNames))
d.FieldU6("nal_unit_type", d.MapUToStrSym(hevcNALNames))
numNals := d.FieldU16("num_nalus")
d.FieldArray("nals", func(d *decode.D) {
for i := uint64(0); i < numNals; i++ {

View File

@ -68,7 +68,7 @@ var hevcNALNames = decode.UToStr{
func hevcNALUDecode(d *decode.D, in interface{}) interface{} {
d.FieldBool("forbidden_zero_bit")
nalType := d.FieldU6("nal_unit_type", d.MapUToStr(hevcNALNames))
nalType := d.FieldU6("nal_unit_type", d.MapUToStrSym(hevcNALNames))
d.FieldU6("nuh_layer_id")
d.FieldU3("nuh_temporal_id_plus1")
unescapedBb := decode.MustNewBitBufFromReader(d, decode.NALUnescapeReader{Reader: d.BitBufRange(d.Pos(), d.BitsLeft())})

View File

@ -234,19 +234,19 @@ func frameDecode(d *decode.D, in interface{}) interface{} {
}
})
paddingBytes = d.FieldU1("padding", d.MapUToStr(decode.UToStr{
paddingBytes = d.FieldU1("padding", d.MapUToStrSym(decode.UToStr{
0: "Not padded",
1: "Padded",
}), d.Bin)
d.FieldU1("private")
channelsIndex := d.FieldU2("channels", d.MapUToStr(decode.UToStr{
channelsIndex := d.FieldU2("channels", d.MapUToStrSym(decode.UToStr{
0b00: "Stereo",
0b01: "Joint stereo",
0b10: "Dual",
0b11: "Mono",
}), d.Bin)
isStereo = channelsIndex != 0b11
d.FieldU2("channel_mode", d.MapUToStr(decode.UToStr{
d.FieldU2("channel_mode", d.MapUToStrSym(decode.UToStr{
0b00: "None",
0b01: "Intensity stereo",
0b10: "MS stereo",
@ -254,7 +254,7 @@ func frameDecode(d *decode.D, in interface{}) interface{} {
}), d.Bin)
d.FieldU1("copyright")
d.FieldU1("original")
d.FieldU2("emphasis", d.MapUToStr(decode.UToStr{
d.FieldU2("emphasis", d.MapUToStrSym(decode.UToStr{
0b00: "None",
0b01: "50/15",
0b10: "reserved",
@ -314,7 +314,7 @@ func frameDecode(d *decode.D, in interface{}) interface{} {
blocksplitFlag := d.FieldU1("blocksplit_flag")
if blocksplitFlag == 1 {
d.FieldU2("block_type", d.MapUToStr(blockTypeNames))
d.FieldU2("block_type", d.MapUToStrSym(blockTypeNames))
d.FieldU1("switch_point")
d.FieldU5("table_select0")
d.FieldU5("table_select1")

View File

@ -53,7 +53,7 @@ func ascDecoder(d *decode.D, in interface{}) interface{} {
n = 32 + d.U6()
}
return n
}, d.MapUToStr(format.MPEGAudioObjectTypeNames))
}, d.MapUToStrSym(format.MPEGAudioObjectTypeNames))
d.FieldUScalarFn("sampling_frequency", func(d *decode.D) decode.Scalar {
v := d.U4()
if v == 15 {
@ -64,7 +64,7 @@ func ascDecoder(d *decode.D, in interface{}) interface{} {
}
return decode.Scalar{Description: "invalid"}
})
d.FieldU4("channel_configuration", d.MapUToStr(channelConfigurationNames))
d.FieldU4("channel_configuration", d.MapUToStrSym(channelConfigurationNames))
// TODO: GASpecificConfig etc
d.FieldRawLen("var_aot_or_byte_align", d.BitsLeft())

View File

@ -193,13 +193,13 @@ func odDecodeTag(d *decode.D, edc *esDecodeContext, expectedTagID int, fn func(d
fieldODDecodeTag(d, edc, "sl_config_descr", -1, nil)
},
DecoderConfigDescrTag: func(d *decode.D) {
objectType := d.FieldU8("object_type_indication", d.MapUToStr(format.MpegObjectTypeNames))
objectType := d.FieldU8("object_type_indication", d.MapUToStrSym(format.MpegObjectTypeNames))
edc.decoderConfigs = append(edc.decoderConfigs, format.MpegDecoderConfig{
ObjectType: int(objectType),
})
edc.currentDecoderConfig = &edc.decoderConfigs[len(edc.decoderConfigs)-1]
d.FieldU6("stream_type", d.MapUToStr(streamTypeNames))
d.FieldU6("stream_type", d.MapUToStrSym(streamTypeNames))
d.FieldBool("upstream")
d.FieldBool("specific_info_flag")
d.FieldU24("buffer_size_db")
@ -263,7 +263,7 @@ func odDecodeTag(d *decode.D, edc *esDecodeContext, expectedTagID int, fn func(d
// TODO: expectedTagID
tagID := d.FieldU8("tag_id", d.MapUToStr(odTagNames))
tagID := d.FieldU8("tag_id", d.MapUToStrSym(odTagNames))
tagLen := d.FieldUFn("length", esLengthEncoding)
if fn != nil {

View File

@ -129,7 +129,7 @@ func spuDecode(d *decode.D, in interface{}) interface{} {
seenEnd := false
for !seenEnd {
d.FieldStruct("command", func(d *decode.D) {
cmd := d.FieldU8("type", d.MapUToStr(commandNames))
cmd := d.FieldU8("type", d.MapUToStrSym(commandNames))
switch cmd {
case CMD_END:
seenEnd = true

View File

@ -92,11 +92,11 @@ func pngDecode(d *decode.D, in interface{}) interface{} {
d.FieldU32("height")
d.FieldU8("bit_depth")
d.FieldU8("color_type")
d.FieldU8("compression_method", d.MapUToStr(compressionNames))
d.FieldU8("filter_method", d.MapUToStr(decode.UToStr{
d.FieldU8("compression_method", d.MapUToStrSym(compressionNames))
d.FieldU8("filter_method", d.MapUToStrSym(decode.UToStr{
0: "Adaptive filtering",
}))
d.FieldU8("interlace_method", d.MapUToStr(decode.UToStr{
d.FieldU8("interlace_method", d.MapUToStrSym(decode.UToStr{
0: "No interlace",
1: "Adam7 interlace",
}))
@ -111,7 +111,7 @@ func pngDecode(d *decode.D, in interface{}) interface{} {
keywordLen := int(d.PeekFindByte(0, 80))
d.FieldUTF8("keyword", keywordLen)
d.FieldUTF8("null", 1)
compressionMethod := d.FieldU8("compression_method", d.MapUToStr(compressionNames))
compressionMethod := d.FieldU8("compression_method", d.MapUToStrSym(compressionNames))
// +2 to skip null and compression_method
dataLen := (chunkLength - (keywordLen + 2)) * 8
@ -132,7 +132,7 @@ func pngDecode(d *decode.D, in interface{}) interface{} {
profileNameLen := int(d.PeekFindByte(0, 80))
d.FieldUTF8("profile_name", profileNameLen)
d.FieldUTF8("null", 1)
compressionMethod := d.FieldU8("compression_method", d.MapUToStr(compressionNames))
compressionMethod := d.FieldU8("compression_method", d.MapUToStrSym(compressionNames))
// +2 to skip null and compression_method
dataLen := (chunkLength - (profileNameLen + 2)) * 8
@ -176,8 +176,8 @@ func pngDecode(d *decode.D, in interface{}) interface{} {
d.FieldU32("y_offset")
d.FieldU16("delay_num")
d.FieldU16("delay_sep")
d.FieldU8("dispose_op", d.MapUToStr(disposeOpNames))
d.FieldU8("blend_op", d.MapUToStr(blendOpNames))
d.FieldU8("dispose_op", d.MapUToStrSym(disposeOpNames))
d.FieldU8("blend_op", d.MapUToStrSym(blendOpNames))
case "fdAT":
d.FieldU32("sequence_number")
d.FieldRawLen("data", int64(chunkLength-4)*8)

View File

@ -99,8 +99,8 @@ func decodeIfd(d *decode.D, s *strips, tagNames map[uint64]string) int64 {
d.FieldArray("entries", func(d *decode.D) {
for i := uint64(0); i < numberOfFields; i++ {
d.FieldStruct("entry", func(d *decode.D) {
tag := d.FieldU16("tag", d.MapUToStr(tagNames), d.Hex)
typ := d.FieldU16("type", d.MapUToStr(typeNames))
tag := d.FieldU16("tag", d.MapUToStrSym(tagNames), d.Hex)
typ := d.FieldU16("type", d.MapUToStrSym(typeNames))
count := d.FieldU32("count")
// TODO: short values stored in valueOffset directly?
valueOrByteOffset := d.FieldU32("value_offset")
@ -148,7 +148,7 @@ func decodeIfd(d *decode.D, s *strips, tagNames map[uint64]string) int64 {
}
case typ == ASCII:
d.RangeFn(int64(valueByteOffset*8), int64(valueByteSize*8), func(d *decode.D) {
d.FieldUTF8NullTerminatedLen("value", int(valueByteSize))
d.FieldUTF8NullFixedLen("value", int(valueByteSize))
})
case typ == BYTE:
d.RangeFn(int64(valueByteOffset*8), int64(valueByteSize*8), func(d *decode.D) {
@ -206,7 +206,7 @@ func decodeIfd(d *decode.D, s *strips, tagNames map[uint64]string) int64 {
}
func tiffDecode(d *decode.D, in interface{}) interface{} {
endian := d.FieldU32("endian", d.MapUToStr(endianNames), d.Hex)
endian := d.FieldU32("endian", d.MapUToStrSym(endianNames), d.Hex)
switch endian {
case littleEndian:

View File

@ -36,7 +36,7 @@ func vp8Decode(d *decode.D, in interface{}) interface{} {
firstPartSize0 := d.FieldU3("first_part_size0")
d.FieldU1("show_frame")
version := d.FieldU3("version")
keyFrameV := d.FieldBool("frame_type", d.MapBoolToStr(decode.BoolToStr{true: "non_key_frame", false: "key_frame"}))
keyFrameV := d.FieldBool("frame_type", d.MapBoolToStrSym(decode.BoolToStr{true: "non_key_frame", false: "key_frame"}))
firstPartSize1 := d.FieldU16LE("first_part_size1")
firstPartSize := firstPartSize0 | firstPartSize1<<3

View File

@ -21,18 +21,18 @@ func init() {
func vp9CFMDecode(d *decode.D, in interface{}) interface{} {
for d.NotEnd() {
d.FieldStruct("feature", func(d *decode.D) {
id := d.FieldU8("id", d.MapUToStr(vp9FeatureIDNames))
id := d.FieldU8("id", d.MapUToStrSym(vp9FeatureIDNames))
l := d.FieldU8("length")
d.LenFn(int64(l)*8, func(d *decode.D) {
switch id {
case vp9FeatureProfile:
d.FieldU8("profile")
case vp9FeatureLevel:
d.FieldU8("level", d.MapUToStr(vpxLevelNames))
d.FieldU8("level", d.MapUToStrSym(vpxLevelNames))
case vp9FeatureBitDepth:
d.FieldU8("bit_depth")
case vp9FeatureChromaSubsampling:
d.FieldU8("chroma_subsampling", d.MapUToStr(vpxChromeSubsamplingNames))
d.FieldU8("chroma_subsampling", d.MapUToStrSym(vpxChromeSubsamplingNames))
default:
d.FieldRawLen("data", d.BitsLeft())
}

View File

@ -72,7 +72,7 @@ func vp9DecodeColorConfig(d *decode.D, profile int) {
}
}
d.FieldValueU("bit_depth", uint64(bitDepth))
colorSpace := d.FieldU3("color_space", d.MapUToStr(vp9ColorSpaceNames))
colorSpace := d.FieldU3("color_space", d.MapUToStrSym(vp9ColorSpaceNames))
_, colorSpaceOk := vp9ColorSpaceNames[colorSpace]
if !colorSpaceOk || colorSpace != CS_RGB {
d.FieldU1("color_range")
@ -117,7 +117,7 @@ func vp9Decode(d *decode.D, in interface{}) interface{} {
return nil
}
frameType := d.FieldBool("frame_type", d.MapBoolToStr(decode.BoolToStr{true: "non_key_frame", false: "key_frame"}))
frameType := d.FieldBool("frame_type", d.MapBoolToStrSym(decode.BoolToStr{true: "non_key_frame", false: "key_frame"}))
d.FieldU1("show_frame")
d.FieldU1("error_resilient_mode")

View File

@ -18,9 +18,9 @@ func init() {
func vpxCCRDecode(d *decode.D, in interface{}) interface{} {
d.FieldU8("profile")
d.FieldU8("level", d.MapUToStr(vpxLevelNames))
d.FieldU8("level", d.MapUToStrSym(vpxLevelNames))
d.FieldU4("bit_depth")
d.FieldU3("chroma_subsampling", d.MapUToStr(vpxChromeSubsamplingNames))
d.FieldU3("chroma_subsampling", d.MapUToStrSym(vpxChromeSubsamplingNames))
d.FieldU1("video_full_range_flag")
d.FieldU8("colour_primaries")
d.FieldU8("transfer_characteristics")

View File

@ -130,7 +130,7 @@ func decodeChunk(d *decode.D, expectedChunkID string, stringData bool) int64 { /
decodeChunks(d, false)
},
"fmt": func(d *decode.D) {
audioFormat := d.FieldU16LE("audio_format", d.MapUToStr(audioFormatName))
audioFormat := d.FieldU16LE("audio_format", d.MapUToStrSym(audioFormatName))
d.FieldU16LE("num_channels")
d.FieldU32LE("sample_rate")
d.FieldU32LE("byte_rate")

View File

@ -388,7 +388,7 @@ func (d *D) tryText(nBytes int, e encoding.Encoding) (string, error) {
// read length prefixed text (ex pascal short string)
// lBits length prefix
// fixedBytes if != -1 read nBytes but trim to length
func (d *D) tryLenPrefixedText(lenBits int, fixedBytes int, e encoding.Encoding) (string, error) {
func (d *D) tryTextLenPrefixed(lenBits int, fixedBytes int, e encoding.Encoding) (string, error) {
p := d.Pos()
l, err := d.bits(lenBits)
if err != nil {
@ -412,7 +412,7 @@ func (d *D) tryLenPrefixedText(lenBits int, fixedBytes int, e encoding.Encoding)
return e.NewDecoder().String(string(bs[0:l]))
}
func (d *D) tryNullTerminatedText(nullBytes int, e encoding.Encoding) (string, error) {
func (d *D) tryTextNull(nullBytes int, e encoding.Encoding) (string, error) {
p := d.Pos()
peekBits, _, err := d.TryPeekFind(nullBytes*8, 8, -1, func(v uint64) bool { return v == 0 })
if err != nil {
@ -428,7 +428,7 @@ func (d *D) tryNullTerminatedText(nullBytes int, e encoding.Encoding) (string, e
return e.NewDecoder().String(string(bs[0 : n-nullBytes]))
}
func (d *D) tryNullTerminatedLenText(fixedBytes int, e encoding.Encoding) (string, error) {
func (d *D) tryTextNullLen(fixedBytes int, e encoding.Encoding) (string, error) {
bs, err := d.bitBuf.BytesLen(fixedBytes)
if err != nil {
return "", err

File diff suppressed because it is too large Load Diff

View File

@ -5,560 +5,149 @@
"S": {"go_type": "int64", "zero": "0", "compare": "a == b"},
"F": {"go_type": "float64", "map_from": false, "zero": "0", "compare": "a == b"},
"Bool": {"go_type": "bool", "zero": "false", "compare": "a == b"},
"BitBuf": {
"go_type": "*bitio.Buffer",
"zero": "nil",
"map_from": false,
"map_to": false
}
"BitBuf": {"go_type": "*bitio.Buffer", "zero": "nil", "map_from": false, "map_to": false}
},
"readers": [
{
"name": "Raw",
"type": "BitBuf",
"variants": [
{
"name": "Len",
"args": "nBits",
"param": "nBits int64",
"call": "d.tryBitBuf(nBits)"
}
]
"variants": [ {"name": "Len", "args": "nBits", "params": "nBits int64", "call": "d.tryBitBuf(nBits)", "doc": "nBits raw bits"} ]
},
{
"name": "Bool",
"type": "Bool",
"variants": [ {"name": "", "args": "", "param": "", "call": "d.tryBool()"} ]
"variants": [ {"name": "", "args": "", "params": "", "call": "d.tryBool()", "doc": "1 bit boolean"} ]
},
{
"name": "U",
"type": "U",
"variants": [
{"name": "", "args": "nBits", "params": "nBits int", "call": "d.tryUE(nBits, d.Endian)", "doc": "nBits bits unsigned integer in current endian"},
{
"name": "E",
"args": "nBits, endian",
"param": "nBits int, endian Endian",
"call": "d.tryUE(nBits, endian)"
"params": "nBits int, endian Endian",
"call": "d.tryUE(nBits, endian)",
"doc": "nBits unsigned integer in specified endian"
},
{
"name": "",
"args": "nBits",
"param": "nBits int",
"call": "d.tryUE(nBits, d.Endian)"
},
{"name": "1", "args": "", "param": "", "call": "d.tryUE(1, d.Endian)"},
{"name": "2", "args": "", "param": "", "call": "d.tryUE(2, d.Endian)"},
{"name": "3", "args": "", "param": "", "call": "d.tryUE(3, d.Endian)"},
{"name": "4", "args": "", "param": "", "call": "d.tryUE(4, d.Endian)"},
{"name": "5", "args": "", "param": "", "call": "d.tryUE(5, d.Endian)"},
{"name": "6", "args": "", "param": "", "call": "d.tryUE(6, d.Endian)"},
{"name": "7", "args": "", "param": "", "call": "d.tryUE(7, d.Endian)"},
{"name": "8", "args": "", "param": "", "call": "d.tryUE(8, d.Endian)"},
{"name": "9", "args": "", "param": "", "call": "d.tryUE(9, d.Endian)"},
{"name": "10", "args": "", "param": "", "call": "d.tryUE(10, d.Endian)"},
{"name": "11", "args": "", "param": "", "call": "d.tryUE(11, d.Endian)"},
{"name": "12", "args": "", "param": "", "call": "d.tryUE(12, d.Endian)"},
{"name": "13", "args": "", "param": "", "call": "d.tryUE(13, d.Endian)"},
{"name": "14", "args": "", "param": "", "call": "d.tryUE(14, d.Endian)"},
{"name": "15", "args": "", "param": "", "call": "d.tryUE(15, d.Endian)"},
{"name": "16", "args": "", "param": "", "call": "d.tryUE(16, d.Endian)"},
{"name": "17", "args": "", "param": "", "call": "d.tryUE(17, d.Endian)"},
{"name": "18", "args": "", "param": "", "call": "d.tryUE(18, d.Endian)"},
{"name": "19", "args": "", "param": "", "call": "d.tryUE(19, d.Endian)"},
{"name": "20", "args": "", "param": "", "call": "d.tryUE(20, d.Endian)"},
{"name": "21", "args": "", "param": "", "call": "d.tryUE(21, d.Endian)"},
{"name": "22", "args": "", "param": "", "call": "d.tryUE(22, d.Endian)"},
{"name": "23", "args": "", "param": "", "call": "d.tryUE(23, d.Endian)"},
{"name": "24", "args": "", "param": "", "call": "d.tryUE(24, d.Endian)"},
{"name": "25", "args": "", "param": "", "call": "d.tryUE(25, d.Endian)"},
{"name": "26", "args": "", "param": "", "call": "d.tryUE(26, d.Endian)"},
{"name": "27", "args": "", "param": "", "call": "d.tryUE(27, d.Endian)"},
{"name": "28", "args": "", "param": "", "call": "d.tryUE(28, d.Endian)"},
{"name": "29", "args": "", "param": "", "call": "d.tryUE(29, d.Endian)"},
{"name": "30", "args": "", "param": "", "call": "d.tryUE(30, d.Endian)"},
{"name": "31", "args": "", "param": "", "call": "d.tryUE(31, d.Endian)"},
{"name": "32", "args": "", "param": "", "call": "d.tryUE(32, d.Endian)"},
{"name": "33", "args": "", "param": "", "call": "d.tryUE(33, d.Endian)"},
{"name": "34", "args": "", "param": "", "call": "d.tryUE(34, d.Endian)"},
{"name": "35", "args": "", "param": "", "call": "d.tryUE(35, d.Endian)"},
{"name": "36", "args": "", "param": "", "call": "d.tryUE(36, d.Endian)"},
{"name": "37", "args": "", "param": "", "call": "d.tryUE(37, d.Endian)"},
{"name": "38", "args": "", "param": "", "call": "d.tryUE(38, d.Endian)"},
{"name": "39", "args": "", "param": "", "call": "d.tryUE(39, d.Endian)"},
{"name": "40", "args": "", "param": "", "call": "d.tryUE(40, d.Endian)"},
{"name": "41", "args": "", "param": "", "call": "d.tryUE(41, d.Endian)"},
{"name": "42", "args": "", "param": "", "call": "d.tryUE(42, d.Endian)"},
{"name": "43", "args": "", "param": "", "call": "d.tryUE(43, d.Endian)"},
{"name": "44", "args": "", "param": "", "call": "d.tryUE(44, d.Endian)"},
{"name": "45", "args": "", "param": "", "call": "d.tryUE(45, d.Endian)"},
{"name": "46", "args": "", "param": "", "call": "d.tryUE(46, d.Endian)"},
{"name": "47", "args": "", "param": "", "call": "d.tryUE(47, d.Endian)"},
{"name": "48", "args": "", "param": "", "call": "d.tryUE(48, d.Endian)"},
{"name": "49", "args": "", "param": "", "call": "d.tryUE(49, d.Endian)"},
{"name": "50", "args": "", "param": "", "call": "d.tryUE(50, d.Endian)"},
{"name": "51", "args": "", "param": "", "call": "d.tryUE(51, d.Endian)"},
{"name": "52", "args": "", "param": "", "call": "d.tryUE(52, d.Endian)"},
{"name": "53", "args": "", "param": "", "call": "d.tryUE(53, d.Endian)"},
{"name": "54", "args": "", "param": "", "call": "d.tryUE(54, d.Endian)"},
{"name": "55", "args": "", "param": "", "call": "d.tryUE(55, d.Endian)"},
{"name": "56", "args": "", "param": "", "call": "d.tryUE(56, d.Endian)"},
{"name": "57", "args": "", "param": "", "call": "d.tryUE(57, d.Endian)"},
{"name": "58", "args": "", "param": "", "call": "d.tryUE(58, d.Endian)"},
{"name": "59", "args": "", "param": "", "call": "d.tryUE(59, d.Endian)"},
{"name": "60", "args": "", "param": "", "call": "d.tryUE(60, d.Endian)"},
{"name": "61", "args": "", "param": "", "call": "d.tryUE(61, d.Endian)"},
{"name": "62", "args": "", "param": "", "call": "d.tryUE(62, d.Endian)"},
{"name": "63", "args": "", "param": "", "call": "d.tryUE(63, d.Endian)"},
{"name": "64", "args": "", "param": "", "call": "d.tryUE(64, d.Endian)"},
{"name": "8LE", "args": "", "param": "", "call": "d.tryUE(8, LittleEndian)"},
{"name": "9LE", "args": "", "param": "", "call": "d.tryUE(9, LittleEndian)"},
{"name": "10LE", "args": "", "param": "", "call": "d.tryUE(10, LittleEndian)"},
{"name": "11LE", "args": "", "param": "", "call": "d.tryUE(11, LittleEndian)"},
{"name": "12LE", "args": "", "param": "", "call": "d.tryUE(12, LittleEndian)"},
{"name": "13LE", "args": "", "param": "", "call": "d.tryUE(13, LittleEndian)"},
{"name": "14LE", "args": "", "param": "", "call": "d.tryUE(14, LittleEndian)"},
{"name": "15LE", "args": "", "param": "", "call": "d.tryUE(15, LittleEndian)"},
{"name": "16LE", "args": "", "param": "", "call": "d.tryUE(16, LittleEndian)"},
{"name": "17LE", "args": "", "param": "", "call": "d.tryUE(17, LittleEndian)"},
{"name": "18LE", "args": "", "param": "", "call": "d.tryUE(18, LittleEndian)"},
{"name": "19LE", "args": "", "param": "", "call": "d.tryUE(19, LittleEndian)"},
{"name": "20LE", "args": "", "param": "", "call": "d.tryUE(20, LittleEndian)"},
{"name": "21LE", "args": "", "param": "", "call": "d.tryUE(21, LittleEndian)"},
{"name": "22LE", "args": "", "param": "", "call": "d.tryUE(22, LittleEndian)"},
{"name": "23LE", "args": "", "param": "", "call": "d.tryUE(23, LittleEndian)"},
{"name": "24LE", "args": "", "param": "", "call": "d.tryUE(24, LittleEndian)"},
{"name": "25LE", "args": "", "param": "", "call": "d.tryUE(25, LittleEndian)"},
{"name": "26LE", "args": "", "param": "", "call": "d.tryUE(26, LittleEndian)"},
{"name": "27LE", "args": "", "param": "", "call": "d.tryUE(27, LittleEndian)"},
{"name": "28LE", "args": "", "param": "", "call": "d.tryUE(28, LittleEndian)"},
{"name": "29LE", "args": "", "param": "", "call": "d.tryUE(29, LittleEndian)"},
{"name": "30LE", "args": "", "param": "", "call": "d.tryUE(30, LittleEndian)"},
{"name": "31LE", "args": "", "param": "", "call": "d.tryUE(31, LittleEndian)"},
{"name": "32LE", "args": "", "param": "", "call": "d.tryUE(32, LittleEndian)"},
{"name": "33LE", "args": "", "param": "", "call": "d.tryUE(33, LittleEndian)"},
{"name": "34LE", "args": "", "param": "", "call": "d.tryUE(34, LittleEndian)"},
{"name": "35LE", "args": "", "param": "", "call": "d.tryUE(35, LittleEndian)"},
{"name": "36LE", "args": "", "param": "", "call": "d.tryUE(36, LittleEndian)"},
{"name": "37LE", "args": "", "param": "", "call": "d.tryUE(37, LittleEndian)"},
{"name": "38LE", "args": "", "param": "", "call": "d.tryUE(38, LittleEndian)"},
{"name": "39LE", "args": "", "param": "", "call": "d.tryUE(39, LittleEndian)"},
{"name": "40LE", "args": "", "param": "", "call": "d.tryUE(40, LittleEndian)"},
{"name": "41LE", "args": "", "param": "", "call": "d.tryUE(41, LittleEndian)"},
{"name": "42LE", "args": "", "param": "", "call": "d.tryUE(42, LittleEndian)"},
{"name": "43LE", "args": "", "param": "", "call": "d.tryUE(43, LittleEndian)"},
{"name": "44LE", "args": "", "param": "", "call": "d.tryUE(44, LittleEndian)"},
{"name": "45LE", "args": "", "param": "", "call": "d.tryUE(45, LittleEndian)"},
{"name": "46LE", "args": "", "param": "", "call": "d.tryUE(46, LittleEndian)"},
{"name": "47LE", "args": "", "param": "", "call": "d.tryUE(47, LittleEndian)"},
{"name": "48LE", "args": "", "param": "", "call": "d.tryUE(48, LittleEndian)"},
{"name": "49LE", "args": "", "param": "", "call": "d.tryUE(49, LittleEndian)"},
{"name": "50LE", "args": "", "param": "", "call": "d.tryUE(50, LittleEndian)"},
{"name": "51LE", "args": "", "param": "", "call": "d.tryUE(51, LittleEndian)"},
{"name": "52LE", "args": "", "param": "", "call": "d.tryUE(52, LittleEndian)"},
{"name": "53LE", "args": "", "param": "", "call": "d.tryUE(53, LittleEndian)"},
{"name": "54LE", "args": "", "param": "", "call": "d.tryUE(54, LittleEndian)"},
{"name": "55LE", "args": "", "param": "", "call": "d.tryUE(55, LittleEndian)"},
{"name": "56LE", "args": "", "param": "", "call": "d.tryUE(56, LittleEndian)"},
{"name": "57LE", "args": "", "param": "", "call": "d.tryUE(57, LittleEndian)"},
{"name": "58LE", "args": "", "param": "", "call": "d.tryUE(58, LittleEndian)"},
{"name": "59LE", "args": "", "param": "", "call": "d.tryUE(59, LittleEndian)"},
{"name": "60LE", "args": "", "param": "", "call": "d.tryUE(60, LittleEndian)"},
{"name": "61LE", "args": "", "param": "", "call": "d.tryUE(61, LittleEndian)"},
{"name": "62LE", "args": "", "param": "", "call": "d.tryUE(62, LittleEndian)"},
{"name": "63LE", "args": "", "param": "", "call": "d.tryUE(63, LittleEndian)"},
{"name": "64LE", "args": "", "param": "", "call": "d.tryUE(64, LittleEndian)"},
{"name": "8BE", "args": "", "param": "", "call": "d.tryUE(8, BigEndian)"},
{"name": "9BE", "args": "", "param": "", "call": "d.tryUE(9, BigEndian)"},
{"name": "10BE", "args": "", "param": "", "call": "d.tryUE(10, BigEndian)"},
{"name": "11BE", "args": "", "param": "", "call": "d.tryUE(11, BigEndian)"},
{"name": "12BE", "args": "", "param": "", "call": "d.tryUE(12, BigEndian)"},
{"name": "13BE", "args": "", "param": "", "call": "d.tryUE(13, BigEndian)"},
{"name": "14BE", "args": "", "param": "", "call": "d.tryUE(14, BigEndian)"},
{"name": "15BE", "args": "", "param": "", "call": "d.tryUE(15, BigEndian)"},
{"name": "16BE", "args": "", "param": "", "call": "d.tryUE(16, BigEndian)"},
{"name": "17BE", "args": "", "param": "", "call": "d.tryUE(17, BigEndian)"},
{"name": "18BE", "args": "", "param": "", "call": "d.tryUE(18, BigEndian)"},
{"name": "19BE", "args": "", "param": "", "call": "d.tryUE(19, BigEndian)"},
{"name": "20BE", "args": "", "param": "", "call": "d.tryUE(20, BigEndian)"},
{"name": "21BE", "args": "", "param": "", "call": "d.tryUE(21, BigEndian)"},
{"name": "22BE", "args": "", "param": "", "call": "d.tryUE(22, BigEndian)"},
{"name": "23BE", "args": "", "param": "", "call": "d.tryUE(23, BigEndian)"},
{"name": "24BE", "args": "", "param": "", "call": "d.tryUE(24, BigEndian)"},
{"name": "25BE", "args": "", "param": "", "call": "d.tryUE(25, BigEndian)"},
{"name": "26BE", "args": "", "param": "", "call": "d.tryUE(26, BigEndian)"},
{"name": "27BE", "args": "", "param": "", "call": "d.tryUE(27, BigEndian)"},
{"name": "28BE", "args": "", "param": "", "call": "d.tryUE(28, BigEndian)"},
{"name": "29BE", "args": "", "param": "", "call": "d.tryUE(29, BigEndian)"},
{"name": "30BE", "args": "", "param": "", "call": "d.tryUE(30, BigEndian)"},
{"name": "31BE", "args": "", "param": "", "call": "d.tryUE(31, BigEndian)"},
{"name": "32BE", "args": "", "param": "", "call": "d.tryUE(32, BigEndian)"},
{"name": "33BE", "args": "", "param": "", "call": "d.tryUE(33, BigEndian)"},
{"name": "34BE", "args": "", "param": "", "call": "d.tryUE(34, BigEndian)"},
{"name": "35BE", "args": "", "param": "", "call": "d.tryUE(35, BigEndian)"},
{"name": "36BE", "args": "", "param": "", "call": "d.tryUE(36, BigEndian)"},
{"name": "37BE", "args": "", "param": "", "call": "d.tryUE(37, BigEndian)"},
{"name": "38BE", "args": "", "param": "", "call": "d.tryUE(38, BigEndian)"},
{"name": "39BE", "args": "", "param": "", "call": "d.tryUE(39, BigEndian)"},
{"name": "40BE", "args": "", "param": "", "call": "d.tryUE(40, BigEndian)"},
{"name": "41BE", "args": "", "param": "", "call": "d.tryUE(41, BigEndian)"},
{"name": "42BE", "args": "", "param": "", "call": "d.tryUE(42, BigEndian)"},
{"name": "43BE", "args": "", "param": "", "call": "d.tryUE(43, BigEndian)"},
{"name": "44BE", "args": "", "param": "", "call": "d.tryUE(44, BigEndian)"},
{"name": "45BE", "args": "", "param": "", "call": "d.tryUE(45, BigEndian)"},
{"name": "46BE", "args": "", "param": "", "call": "d.tryUE(46, BigEndian)"},
{"name": "47BE", "args": "", "param": "", "call": "d.tryUE(47, BigEndian)"},
{"name": "48BE", "args": "", "param": "", "call": "d.tryUE(48, BigEndian)"},
{"name": "49BE", "args": "", "param": "", "call": "d.tryUE(49, BigEndian)"},
{"name": "50BE", "args": "", "param": "", "call": "d.tryUE(50, BigEndian)"},
{"name": "51BE", "args": "", "param": "", "call": "d.tryUE(51, BigEndian)"},
{"name": "52BE", "args": "", "param": "", "call": "d.tryUE(52, BigEndian)"},
{"name": "53BE", "args": "", "param": "", "call": "d.tryUE(53, BigEndian)"},
{"name": "54BE", "args": "", "param": "", "call": "d.tryUE(54, BigEndian)"},
{"name": "55BE", "args": "", "param": "", "call": "d.tryUE(55, BigEndian)"},
{"name": "56BE", "args": "", "param": "", "call": "d.tryUE(56, BigEndian)"},
{"name": "57BE", "args": "", "param": "", "call": "d.tryUE(57, BigEndian)"},
{"name": "58BE", "args": "", "param": "", "call": "d.tryUE(58, BigEndian)"},
{"name": "59BE", "args": "", "param": "", "call": "d.tryUE(59, BigEndian)"},
{"name": "60BE", "args": "", "param": "", "call": "d.tryUE(60, BigEndian)"},
{"name": "61BE", "args": "", "param": "", "call": "d.tryUE(61, BigEndian)"},
{"name": "62BE", "args": "", "param": "", "call": "d.tryUE(62, BigEndian)"},
{"name": "63BE", "args": "", "param": "", "call": "d.tryUE(63, BigEndian)"},
{"name": "64BE", "args": "", "param": "", "call": "d.tryUE(64, BigEndian)"}
{ "name": "$n", "range": [1, 64], "args": "", "params": "", "call": "d.tryUE($n, d.Endian)", "doc": "$n bit unsigned integer in current endian" },
{ "name": "$nLE", "range": [8, 64], "args": "", "params": "", "call": "d.tryUE($n, LittleEndian)", "doc": "$n bit unsigned integer in little-endian" },
{ "name": "$nBE", "range": [8, 64], "args": "", "params": "", "call": "d.tryUE($n, BigEndian)", "doc": "$n bit unsigned integer in big-endian" }
]
},
{
"name": "S",
"type": "S",
"variants": [
{"name": "", "args": "nBits", "params": "nBits int", "call": "d.trySE(nBits, d.Endian)", "doc": "nBits bits signed integer in current endian"},
{
"name": "E",
"args": "nBits, endian",
"param": "nBits int, endian Endian",
"call": "d.trySE(nBits, endian)"
"params": "nBits int, endian Endian",
"call": "d.trySE(nBits, endian)",
"doc": "nBits signed integer in specified endian"
},
{
"name": "",
"args": "nBits",
"param": "nBits int",
"call": "d.trySE(nBits, d.Endian)"
},
{"name": "1", "args": "", "param": "", "call": "d.trySE(1, d.Endian)"},
{"name": "2", "args": "", "param": "", "call": "d.trySE(2, d.Endian)"},
{"name": "3", "args": "", "param": "", "call": "d.trySE(3, d.Endian)"},
{"name": "4", "args": "", "param": "", "call": "d.trySE(4, d.Endian)"},
{"name": "5", "args": "", "param": "", "call": "d.trySE(5, d.Endian)"},
{"name": "6", "args": "", "param": "", "call": "d.trySE(6, d.Endian)"},
{"name": "7", "args": "", "param": "", "call": "d.trySE(7, d.Endian)"},
{"name": "8", "args": "", "param": "", "call": "d.trySE(8, d.Endian)"},
{"name": "9", "args": "", "param": "", "call": "d.trySE(9, d.Endian)"},
{"name": "10", "args": "", "param": "", "call": "d.trySE(10, d.Endian)"},
{"name": "11", "args": "", "param": "", "call": "d.trySE(11, d.Endian)"},
{"name": "12", "args": "", "param": "", "call": "d.trySE(12, d.Endian)"},
{"name": "13", "args": "", "param": "", "call": "d.trySE(13, d.Endian)"},
{"name": "14", "args": "", "param": "", "call": "d.trySE(14, d.Endian)"},
{"name": "15", "args": "", "param": "", "call": "d.trySE(15, d.Endian)"},
{"name": "16", "args": "", "param": "", "call": "d.trySE(16, d.Endian)"},
{"name": "17", "args": "", "param": "", "call": "d.trySE(17, d.Endian)"},
{"name": "18", "args": "", "param": "", "call": "d.trySE(18, d.Endian)"},
{"name": "19", "args": "", "param": "", "call": "d.trySE(19, d.Endian)"},
{"name": "20", "args": "", "param": "", "call": "d.trySE(20, d.Endian)"},
{"name": "21", "args": "", "param": "", "call": "d.trySE(21, d.Endian)"},
{"name": "22", "args": "", "param": "", "call": "d.trySE(22, d.Endian)"},
{"name": "23", "args": "", "param": "", "call": "d.trySE(23, d.Endian)"},
{"name": "24", "args": "", "param": "", "call": "d.trySE(24, d.Endian)"},
{"name": "25", "args": "", "param": "", "call": "d.trySE(25, d.Endian)"},
{"name": "26", "args": "", "param": "", "call": "d.trySE(26, d.Endian)"},
{"name": "27", "args": "", "param": "", "call": "d.trySE(27, d.Endian)"},
{"name": "28", "args": "", "param": "", "call": "d.trySE(28, d.Endian)"},
{"name": "29", "args": "", "param": "", "call": "d.trySE(29, d.Endian)"},
{"name": "30", "args": "", "param": "", "call": "d.trySE(30, d.Endian)"},
{"name": "31", "args": "", "param": "", "call": "d.trySE(31, d.Endian)"},
{"name": "32", "args": "", "param": "", "call": "d.trySE(32, d.Endian)"},
{"name": "33", "args": "", "param": "", "call": "d.trySE(33, d.Endian)"},
{"name": "34", "args": "", "param": "", "call": "d.trySE(34, d.Endian)"},
{"name": "35", "args": "", "param": "", "call": "d.trySE(35, d.Endian)"},
{"name": "36", "args": "", "param": "", "call": "d.trySE(36, d.Endian)"},
{"name": "37", "args": "", "param": "", "call": "d.trySE(37, d.Endian)"},
{"name": "38", "args": "", "param": "", "call": "d.trySE(38, d.Endian)"},
{"name": "39", "args": "", "param": "", "call": "d.trySE(39, d.Endian)"},
{"name": "40", "args": "", "param": "", "call": "d.trySE(40, d.Endian)"},
{"name": "41", "args": "", "param": "", "call": "d.trySE(41, d.Endian)"},
{"name": "42", "args": "", "param": "", "call": "d.trySE(42, d.Endian)"},
{"name": "43", "args": "", "param": "", "call": "d.trySE(43, d.Endian)"},
{"name": "44", "args": "", "param": "", "call": "d.trySE(44, d.Endian)"},
{"name": "45", "args": "", "param": "", "call": "d.trySE(45, d.Endian)"},
{"name": "46", "args": "", "param": "", "call": "d.trySE(46, d.Endian)"},
{"name": "47", "args": "", "param": "", "call": "d.trySE(47, d.Endian)"},
{"name": "48", "args": "", "param": "", "call": "d.trySE(48, d.Endian)"},
{"name": "49", "args": "", "param": "", "call": "d.trySE(49, d.Endian)"},
{"name": "50", "args": "", "param": "", "call": "d.trySE(50, d.Endian)"},
{"name": "51", "args": "", "param": "", "call": "d.trySE(51, d.Endian)"},
{"name": "52", "args": "", "param": "", "call": "d.trySE(52, d.Endian)"},
{"name": "53", "args": "", "param": "", "call": "d.trySE(53, d.Endian)"},
{"name": "54", "args": "", "param": "", "call": "d.trySE(54, d.Endian)"},
{"name": "55", "args": "", "param": "", "call": "d.trySE(55, d.Endian)"},
{"name": "56", "args": "", "param": "", "call": "d.trySE(56, d.Endian)"},
{"name": "57", "args": "", "param": "", "call": "d.trySE(57, d.Endian)"},
{"name": "58", "args": "", "param": "", "call": "d.trySE(58, d.Endian)"},
{"name": "59", "args": "", "param": "", "call": "d.trySE(59, d.Endian)"},
{"name": "60", "args": "", "param": "", "call": "d.trySE(60, d.Endian)"},
{"name": "61", "args": "", "param": "", "call": "d.trySE(61, d.Endian)"},
{"name": "62", "args": "", "param": "", "call": "d.trySE(62, d.Endian)"},
{"name": "63", "args": "", "param": "", "call": "d.trySE(63, d.Endian)"},
{"name": "64", "args": "", "param": "", "call": "d.trySE(64, d.Endian)"},
{"name": "8LE", "args": "", "param": "", "call": "d.trySE(8, LittleEndian)"},
{"name": "9LE", "args": "", "param": "", "call": "d.trySE(9, LittleEndian)"},
{"name": "10LE", "args": "", "param": "", "call": "d.trySE(10, LittleEndian)"},
{"name": "11LE", "args": "", "param": "", "call": "d.trySE(11, LittleEndian)"},
{"name": "12LE", "args": "", "param": "", "call": "d.trySE(12, LittleEndian)"},
{"name": "13LE", "args": "", "param": "", "call": "d.trySE(13, LittleEndian)"},
{"name": "14LE", "args": "", "param": "", "call": "d.trySE(14, LittleEndian)"},
{"name": "15LE", "args": "", "param": "", "call": "d.trySE(15, LittleEndian)"},
{"name": "16LE", "args": "", "param": "", "call": "d.trySE(16, LittleEndian)"},
{"name": "17LE", "args": "", "param": "", "call": "d.trySE(17, LittleEndian)"},
{"name": "18LE", "args": "", "param": "", "call": "d.trySE(18, LittleEndian)"},
{"name": "19LE", "args": "", "param": "", "call": "d.trySE(19, LittleEndian)"},
{"name": "20LE", "args": "", "param": "", "call": "d.trySE(20, LittleEndian)"},
{"name": "21LE", "args": "", "param": "", "call": "d.trySE(21, LittleEndian)"},
{"name": "22LE", "args": "", "param": "", "call": "d.trySE(22, LittleEndian)"},
{"name": "23LE", "args": "", "param": "", "call": "d.trySE(23, LittleEndian)"},
{"name": "24LE", "args": "", "param": "", "call": "d.trySE(24, LittleEndian)"},
{"name": "25LE", "args": "", "param": "", "call": "d.trySE(25, LittleEndian)"},
{"name": "26LE", "args": "", "param": "", "call": "d.trySE(26, LittleEndian)"},
{"name": "27LE", "args": "", "param": "", "call": "d.trySE(27, LittleEndian)"},
{"name": "28LE", "args": "", "param": "", "call": "d.trySE(28, LittleEndian)"},
{"name": "29LE", "args": "", "param": "", "call": "d.trySE(29, LittleEndian)"},
{"name": "30LE", "args": "", "param": "", "call": "d.trySE(30, LittleEndian)"},
{"name": "31LE", "args": "", "param": "", "call": "d.trySE(31, LittleEndian)"},
{"name": "32LE", "args": "", "param": "", "call": "d.trySE(32, LittleEndian)"},
{"name": "33LE", "args": "", "param": "", "call": "d.trySE(33, LittleEndian)"},
{"name": "34LE", "args": "", "param": "", "call": "d.trySE(34, LittleEndian)"},
{"name": "35LE", "args": "", "param": "", "call": "d.trySE(35, LittleEndian)"},
{"name": "36LE", "args": "", "param": "", "call": "d.trySE(36, LittleEndian)"},
{"name": "37LE", "args": "", "param": "", "call": "d.trySE(37, LittleEndian)"},
{"name": "38LE", "args": "", "param": "", "call": "d.trySE(38, LittleEndian)"},
{"name": "39LE", "args": "", "param": "", "call": "d.trySE(39, LittleEndian)"},
{"name": "40LE", "args": "", "param": "", "call": "d.trySE(40, LittleEndian)"},
{"name": "41LE", "args": "", "param": "", "call": "d.trySE(41, LittleEndian)"},
{"name": "42LE", "args": "", "param": "", "call": "d.trySE(42, LittleEndian)"},
{"name": "43LE", "args": "", "param": "", "call": "d.trySE(43, LittleEndian)"},
{"name": "44LE", "args": "", "param": "", "call": "d.trySE(44, LittleEndian)"},
{"name": "45LE", "args": "", "param": "", "call": "d.trySE(45, LittleEndian)"},
{"name": "46LE", "args": "", "param": "", "call": "d.trySE(46, LittleEndian)"},
{"name": "47LE", "args": "", "param": "", "call": "d.trySE(47, LittleEndian)"},
{"name": "48LE", "args": "", "param": "", "call": "d.trySE(48, LittleEndian)"},
{"name": "49LE", "args": "", "param": "", "call": "d.trySE(49, LittleEndian)"},
{"name": "50LE", "args": "", "param": "", "call": "d.trySE(50, LittleEndian)"},
{"name": "51LE", "args": "", "param": "", "call": "d.trySE(51, LittleEndian)"},
{"name": "52LE", "args": "", "param": "", "call": "d.trySE(52, LittleEndian)"},
{"name": "53LE", "args": "", "param": "", "call": "d.trySE(53, LittleEndian)"},
{"name": "54LE", "args": "", "param": "", "call": "d.trySE(54, LittleEndian)"},
{"name": "55LE", "args": "", "param": "", "call": "d.trySE(55, LittleEndian)"},
{"name": "56LE", "args": "", "param": "", "call": "d.trySE(56, LittleEndian)"},
{"name": "57LE", "args": "", "param": "", "call": "d.trySE(57, LittleEndian)"},
{"name": "58LE", "args": "", "param": "", "call": "d.trySE(58, LittleEndian)"},
{"name": "59LE", "args": "", "param": "", "call": "d.trySE(59, LittleEndian)"},
{"name": "60LE", "args": "", "param": "", "call": "d.trySE(60, LittleEndian)"},
{"name": "61LE", "args": "", "param": "", "call": "d.trySE(61, LittleEndian)"},
{"name": "62LE", "args": "", "param": "", "call": "d.trySE(62, LittleEndian)"},
{"name": "63LE", "args": "", "param": "", "call": "d.trySE(63, LittleEndian)"},
{"name": "64LE", "args": "", "param": "", "call": "d.trySE(64, LittleEndian)"},
{"name": "8BE", "args": "", "param": "", "call": "d.trySE(8, BigEndian)"},
{"name": "9BE", "args": "", "param": "", "call": "d.trySE(9, BigEndian)"},
{"name": "10BE", "args": "", "param": "", "call": "d.trySE(10, BigEndian)"},
{"name": "11BE", "args": "", "param": "", "call": "d.trySE(11, BigEndian)"},
{"name": "12BE", "args": "", "param": "", "call": "d.trySE(12, BigEndian)"},
{"name": "13BE", "args": "", "param": "", "call": "d.trySE(13, BigEndian)"},
{"name": "14BE", "args": "", "param": "", "call": "d.trySE(14, BigEndian)"},
{"name": "15BE", "args": "", "param": "", "call": "d.trySE(15, BigEndian)"},
{"name": "16BE", "args": "", "param": "", "call": "d.trySE(16, BigEndian)"},
{"name": "17BE", "args": "", "param": "", "call": "d.trySE(17, BigEndian)"},
{"name": "18BE", "args": "", "param": "", "call": "d.trySE(18, BigEndian)"},
{"name": "19BE", "args": "", "param": "", "call": "d.trySE(19, BigEndian)"},
{"name": "20BE", "args": "", "param": "", "call": "d.trySE(20, BigEndian)"},
{"name": "21BE", "args": "", "param": "", "call": "d.trySE(21, BigEndian)"},
{"name": "22BE", "args": "", "param": "", "call": "d.trySE(22, BigEndian)"},
{"name": "23BE", "args": "", "param": "", "call": "d.trySE(23, BigEndian)"},
{"name": "24BE", "args": "", "param": "", "call": "d.trySE(24, BigEndian)"},
{"name": "25BE", "args": "", "param": "", "call": "d.trySE(25, BigEndian)"},
{"name": "26BE", "args": "", "param": "", "call": "d.trySE(26, BigEndian)"},
{"name": "27BE", "args": "", "param": "", "call": "d.trySE(27, BigEndian)"},
{"name": "28BE", "args": "", "param": "", "call": "d.trySE(28, BigEndian)"},
{"name": "29BE", "args": "", "param": "", "call": "d.trySE(29, BigEndian)"},
{"name": "30BE", "args": "", "param": "", "call": "d.trySE(30, BigEndian)"},
{"name": "31BE", "args": "", "param": "", "call": "d.trySE(31, BigEndian)"},
{"name": "32BE", "args": "", "param": "", "call": "d.trySE(32, BigEndian)"},
{"name": "33BE", "args": "", "param": "", "call": "d.trySE(33, BigEndian)"},
{"name": "34BE", "args": "", "param": "", "call": "d.trySE(34, BigEndian)"},
{"name": "35BE", "args": "", "param": "", "call": "d.trySE(35, BigEndian)"},
{"name": "36BE", "args": "", "param": "", "call": "d.trySE(36, BigEndian)"},
{"name": "37BE", "args": "", "param": "", "call": "d.trySE(37, BigEndian)"},
{"name": "38BE", "args": "", "param": "", "call": "d.trySE(38, BigEndian)"},
{"name": "39BE", "args": "", "param": "", "call": "d.trySE(39, BigEndian)"},
{"name": "40BE", "args": "", "param": "", "call": "d.trySE(40, BigEndian)"},
{"name": "41BE", "args": "", "param": "", "call": "d.trySE(41, BigEndian)"},
{"name": "42BE", "args": "", "param": "", "call": "d.trySE(42, BigEndian)"},
{"name": "43BE", "args": "", "param": "", "call": "d.trySE(43, BigEndian)"},
{"name": "44BE", "args": "", "param": "", "call": "d.trySE(44, BigEndian)"},
{"name": "45BE", "args": "", "param": "", "call": "d.trySE(45, BigEndian)"},
{"name": "46BE", "args": "", "param": "", "call": "d.trySE(46, BigEndian)"},
{"name": "47BE", "args": "", "param": "", "call": "d.trySE(47, BigEndian)"},
{"name": "48BE", "args": "", "param": "", "call": "d.trySE(48, BigEndian)"},
{"name": "49BE", "args": "", "param": "", "call": "d.trySE(49, BigEndian)"},
{"name": "50BE", "args": "", "param": "", "call": "d.trySE(50, BigEndian)"},
{"name": "51BE", "args": "", "param": "", "call": "d.trySE(51, BigEndian)"},
{"name": "52BE", "args": "", "param": "", "call": "d.trySE(52, BigEndian)"},
{"name": "53BE", "args": "", "param": "", "call": "d.trySE(53, BigEndian)"},
{"name": "54BE", "args": "", "param": "", "call": "d.trySE(54, BigEndian)"},
{"name": "55BE", "args": "", "param": "", "call": "d.trySE(55, BigEndian)"},
{"name": "56BE", "args": "", "param": "", "call": "d.trySE(56, BigEndian)"},
{"name": "57BE", "args": "", "param": "", "call": "d.trySE(57, BigEndian)"},
{"name": "58BE", "args": "", "param": "", "call": "d.trySE(58, BigEndian)"},
{"name": "59BE", "args": "", "param": "", "call": "d.trySE(59, BigEndian)"},
{"name": "60BE", "args": "", "param": "", "call": "d.trySE(60, BigEndian)"},
{"name": "61BE", "args": "", "param": "", "call": "d.trySE(61, BigEndian)"},
{"name": "62BE", "args": "", "param": "", "call": "d.trySE(62, BigEndian)"},
{"name": "63BE", "args": "", "param": "", "call": "d.trySE(63, BigEndian)"},
{"name": "64BE", "args": "", "param": "", "call": "d.trySE(64, BigEndian)"}
{ "name": "$n", "range": [1, 64], "args": "", "params": "", "call": "d.trySE($n, d.Endian)", "doc": "$n bit signed integer in current endian" },
{ "name": "$nLE", "range": [8, 64], "args": "", "params": "", "call": "d.trySE($n, LittleEndian)", "doc": "$n bit signed integer in little-endian" },
{ "name": "$nBE", "range": [8, 64], "args": "", "params": "", "call": "d.trySE($n, BigEndian)", "doc": "$n bit signed integer in big-endian" }
]
},
{
"name": "F",
"type": "F",
"variants": [
{
"name": "E",
"args": "nBits, endian",
"param": "nBits int, endian Endian",
"call": "d.tryFE(nBits, endian)"
},
{
"name": "",
"args": "nBits",
"param": "nBits int",
"call": "d.tryFE(nBits, d.Endian)"
},
{"name": "16", "args": "", "param": "", "call": "d.tryFE(16, d.Endian)"},
{"name": "32", "args": "", "param": "", "call": "d.tryFE(32, d.Endian)"},
{"name": "64", "args": "", "param": "", "call": "d.tryFE(64, d.Endian)"},
{"name": "16LE", "args": "", "param": "", "call": "d.tryFE(16, LittleEndian)"},
{"name": "32LE", "args": "", "param": "", "call": "d.tryFE(32, LittleEndian)"},
{"name": "64LE", "args": "", "param": "", "call": "d.tryFE(64, LittleEndian)"},
{"name": "16BE", "args": "", "param": "", "call": "d.tryFE(16, BigEndian)"},
{"name": "32BE", "args": "", "param": "", "call": "d.tryFE(32, BigEndian)"},
{"name": "64BE", "args": "", "param": "", "call": "d.tryFE(64, BigEndian)"}
{"name": "", "args": "nBits", "params": "nBits int", "call": "d.tryFE(nBits, d.Endian)", "doc": "nBit IEEE 754 float in current endian"},
{"name": "E", "args": "nBits, endian", "params": "nBits int, endian Endian", "call": "d.tryFE(nBits, endian)", "doc": "nBit IEEE 754 float in specified endian"},
{"name": "16", "args": "", "params": "", "call": "d.tryFE(16, d.Endian)", "doc": "16 bit IEEE 754 float in current endian"},
{"name": "32", "args": "", "params": "", "call": "d.tryFE(32, d.Endian)", "doc": "32 bit IEEE 754 float in current endian"},
{"name": "64", "args": "", "params": "", "call": "d.tryFE(64, d.Endian)", "doc": "64 bit IEEE 754 float in current endian"},
{"name": "16LE", "args": "", "params": "", "call": "d.tryFE(16, LittleEndian)", "doc": "16 bit IEEE 754 float in little-endian"},
{"name": "32LE", "args": "", "params": "", "call": "d.tryFE(32, LittleEndian)", "doc": "32 bit IEEE 754 float in little-endian"},
{"name": "64LE", "args": "", "params": "", "call": "d.tryFE(64, LittleEndian)", "doc": "64 bit IEEE 754 float in little-endian"},
{"name": "16BE", "args": "", "params": "", "call": "d.tryFE(16, BigEndian)", "doc": "16 bit IEEE 754 float in big-endian"},
{"name": "32BE", "args": "", "params": "", "call": "d.tryFE(32, BigEndian)", "doc": "32 bit IEEE 754 float in big-endian"},
{"name": "64BE", "args": "", "params": "", "call": "d.tryFE(64, BigEndian)", "doc": "64 bit IEEE 754 float in big-endian"}
]
},
{
"name": "FP",
"type": "F",
"variants": [
{
"name": "E",
"args": "nBits, fBits, endian",
"param": "nBits int, fBits int64, endian Endian",
"call": "d.tryFPE(nBits, fBits, endian)"
},
{
"name": "",
"args": "nBits, fBits",
"param": "nBits int, fBits int64",
"call": "d.tryFPE(nBits, fBits, d.Endian)"
},
{"name": "16", "args": "", "param": "", "call": "d.tryFPE(16, 8, d.Endian)"},
{"name": "32", "args": "", "param": "", "call": "d.tryFPE(32, 16, d.Endian)"},
{"name": "64", "args": "", "param": "", "call": "d.tryFPE(64, 32, d.Endian)"},
{
"name": "16LE",
"args": "",
"param": "",
"call": "d.tryFPE(16, 8, LittleEndian)"
"params": "nBits int, fBits int64",
"call": "d.tryFPE(nBits, fBits, d.Endian)",
"doc": "nBits fixed-point number in current endian"
},
{
"name": "32LE",
"args": "",
"param": "",
"call": "d.tryFPE(32, 16, LittleEndian)"
"name": "E",
"args": "nBits, fBits, endian",
"params": "nBits int, fBits int64, endian Endian",
"call": "d.tryFPE(nBits, fBits, endian)",
"doc": "nBits fixed-point number in specified endian"
},
{
"name": "64LE",
"args": "",
"param": "",
"call": "d.tryFPE(64, 32, LittleEndian)"
},
{"name": "16BE", "args": "", "param": "", "call": "d.tryFPE(16, 8, BigEndian)"},
{"name": "32BE", "args": "", "param": "", "call": "d.tryFPE(32, 16, BigEndian)"},
{"name": "64BE", "args": "", "param": "", "call": "d.tryFPE(64, 32, BigEndian)"}
{"name": "16", "args": "", "params": "", "call": "d.tryFPE(16, 8, d.Endian)", "doc": "16 bit fixed-point number in current endian"},
{"name": "32", "args": "", "params": "", "call": "d.tryFPE(32, 16, d.Endian)", "doc": "32 bit fixed-point number in current endian"},
{"name": "64", "args": "", "params": "", "call": "d.tryFPE(64, 32, d.Endian)", "doc": "64 bit fixed-point number in current endian"},
{"name": "16LE", "args": "", "params": "", "call": "d.tryFPE(16, 8, LittleEndian)", "doc": "16 bit fixed-point number in little-endian"},
{"name": "32LE", "args": "", "params": "", "call": "d.tryFPE(32, 16, LittleEndian)", "doc": "32 bit fixed-point number in little-endian"},
{"name": "64LE", "args": "", "params": "", "call": "d.tryFPE(64, 32, LittleEndian)", "doc": "64 bit fixed-point number in little-endian"},
{"name": "16BE", "args": "", "params": "", "call": "d.tryFPE(16, 8, BigEndian)", "doc": "16 bit fixed-point number in big-endian"},
{"name": "32BE", "args": "", "params": "", "call": "d.tryFPE(32, 16, BigEndian)", "doc": "32 bit fixed-point number in big-endian"},
{"name": "64BE", "args": "", "params": "", "call": "d.tryFPE(64, 32, BigEndian)", "doc": "64 bit fixed-point number in big-endian"}
]
},
{
"name": "Unary",
"type": "U",
"variants": [ {"name": "", "args": "ov", "param": "ov uint64", "call": "d.tryUnary(ov)"} ]
"variants": [ {"name": "", "args": "ov", "params": "ov uint64", "call": "d.tryUnary(ov)", "doc": "unary integer using ov as \"one\" value"} ]
},
{
"type": "Str",
"name": "UTF",
"variants": [
{
"name": "8",
"args": "nBytes",
"param": "nBytes int",
"call": "d.tryText(nBytes, UTF8BOM)"
},
{"name": "8", "args": "nBytes", "params": "nBytes int", "call": "d.tryText(nBytes, UTF8BOM)", "doc": "nBytes bytes UTF8 string"},
{
"name": "16",
"args": "nBytes",
"param": "nBytes int",
"call": "d.tryText(nBytes, UTF16BOM)"
"params": "nBytes int",
"call": "d.tryText(nBytes, UTF16BOM)",
"doc": "nBytes bytes UTF16 string, default big-endian and accepts BOM"
},
{
"name": "16LE",
"args": "nBytes",
"param": "nBytes int",
"call": "d.tryText(nBytes, UTF16LE)"
},
{
"name": "16BE",
"args": "nBytes",
"param": "nBytes int",
"call": "d.tryText(nBytes, UTF16BE)"
}
{"name": "16LE", "args": "nBytes", "params": "nBytes int", "call": "d.tryText(nBytes, UTF16LE)", "doc": "nBytes bytes UTF16 little-endian string"},
{"name": "16BE", "args": "nBytes", "params": "nBytes int", "call": "d.tryText(nBytes, UTF16BE)", "doc": "nBytes bytes UTF16 big-endian string"}
]
},
{
"name": "UTF8ShortString",
"type": "Str",
"variants": [
{"name": "", "args": "", "params": "", "call": "d.tryTextLenPrefixed(8, -1, UTF8BOM)", "doc": "one byte length fixed UTF8 string"},
{
"name": "",
"args": "nBytes",
"param": "nBytes int",
"call": "d.tryLenPrefixedText(8, nBytes, UTF8BOM)"
"name": "FixedLen",
"args": "fixedBytes",
"params": "fixedBytes int",
"call": "d.tryTextLenPrefixed(8, fixedBytes, UTF8BOM)",
"doc": "fixedBytes bytes long one byte length prefixed UTF8 string"
}
]
},
{
"name": "UTF8NullTerminated",
"name": "UTF8Null",
"type": "Str",
"variants": [
{
"name": "",
"args": "",
"param": "",
"call": "d.tryNullTerminatedText(1, UTF8BOM)"
}
]
"variants": [ {"name": "", "args": "", "params": "", "call": "d.tryTextNull(1, UTF8BOM)", "doc": "null terminated UTF8 string"} ]
},
{
"name": "UTF8NullTerminatedLen",
"name": "UTF8NullFixedLen",
"type": "Str",
"variants": [
{
"name": "",
"args": "fixedBytes",
"param": "fixedBytes int",
"call": "d.tryNullTerminatedLenText(fixedBytes, UTF8BOM)"
"params": "fixedBytes int",
"call": "d.tryTextNullLen(fixedBytes, UTF8BOM)",
"doc": "fixedBytes bytes long null terminated UTF8 string"
}
]
}

View File

@ -11,6 +11,7 @@ import (
{{- range $name, $t := $.types }}
// Type {{$name}}
// Actual{{$name}} asserts actual value is a {{$name}} and returns it
func (s Scalar) Actual{{$name}}() {{$t.go_type}} {
v, ok := s.Actual.({{$t.go_type}})
if !ok {
@ -18,6 +19,8 @@ import (
}
return v
}
// Sym{{$name}} asserts symbolic value is a {{$name}} and returns it
func (s Scalar) Sym{{$name}}() {{$t.go_type}} {
v, ok := s.Sym.({{$t.go_type}})
if !ok {
@ -26,6 +29,7 @@ import (
return v
}
// Field{{$name}}ScalarFn adds a field, calls scalar functions and returns actual value as a {{$name}}
func (d *D) Field{{$name}}ScalarFn(name string, fn func(d *D) Scalar, sfns ...ScalarFn) {{$t.go_type}} {
v, err := d.TryFieldScalar(name, func(_ Scalar) (Scalar, error) { return fn(d), nil }, sfns...)
if err != nil {
@ -33,9 +37,13 @@ import (
}
return v.Actual{{$name}}()
}
// Field{{$name}}Fn adds a field, calls {{$t.go_type}} decode function and returns actual value as a {{$name}}
func (d *D) Field{{$name}}Fn(name string, fn func(d *D) {{$t.go_type}}, sfns ...ScalarFn) {{$t.go_type}} {
return d.Field{{$name}}ScalarFn(name, func(d *D) Scalar { return Scalar{Actual: fn(d) } }, sfns...)
}
// TryField{{$name}}ScalarFn tries to add a field, calls scalar functions and returns actual value as a {{$name}}
func (d *D) TryField{{$name}}ScalarFn(name string, fn func(d *D) (Scalar, error), sfns ...ScalarFn) ({{$t.go_type}}, error) {
v, err := d.TryFieldScalar(name, func(_ Scalar) (Scalar, error) { return fn(d) }, sfns...)
if err != nil {
@ -43,6 +51,8 @@ import (
}
return v.Actual{{$name}}(), err
}
// TryField{{$name}}Fn tries to add a field, calls {{$t.go_type}} decode function and returns actual value as a {{$name}}
func (d *D) TryField{{$name}}Fn(name string, fn func(d *D) ({{$t.go_type}}, error), sfns ...ScalarFn) ({{$t.go_type}}, error) {
return d.TryField{{$name}}ScalarFn(name, func(d *D) (Scalar, error) {
v, err := fn(d)
@ -54,6 +64,7 @@ import (
{{- range $name, $t := $.types }}
{{- if $t.compare}}
// Validate/Assert {{$name}}
func (d *D) assert{{$name}}(assert bool, vs ...{{$t.go_type}}) func(s Scalar) (Scalar, error) {
return func(s Scalar) (Scalar, error) {
a := s.Actual{{$name}}()
@ -71,9 +82,11 @@ import (
}
}
// Assert{{$name}} asserts that actual value is one of given {{$t.go_type}} values
func (d *D) Assert{{$name}}(vs ...{{$t.go_type}}) func(s Scalar) (Scalar, error) {
return d.assert{{$name}}(true, vs...)
}
// Validate{{$name}} validates that actual value is one of given {{$t.go_type}} values
func (d *D) Validate{{$name}}(vs ...{{$t.go_type}}) func(s Scalar) (Scalar, error) {
return d.assert{{$name}}(false, vs...)
}
@ -86,6 +99,7 @@ import (
type {{$from_name}}ToScalar map[{{$from.go_type}}]Scalar
// Map{{$from_name}}ToScalar maps {{$from_name}} to a Scalar
func (d *D) Map{{$from_name}}ToScalar(m {{$from_name}}ToScalar) func(s Scalar) (Scalar, error) {
return func(s Scalar) (Scalar, error) {
a := s.Actual{{$from_name}}()
@ -103,7 +117,8 @@ import (
type {{$from_name}}To{{$to_name}} map[{{$from.go_type}}]{{$to.go_type}}
func (d *D) Map{{$from_name}}To{{$to_name}}(m {{$from_name}}To{{$to_name}}) func(s Scalar) (Scalar, error) {
// Map{{$from_name}}To{{$to_name}}Sym maps {{$from_name}} to a symolic {{$to_name}}
func (d *D) Map{{$from_name}}To{{$to_name}}Sym(m {{$from_name}}To{{$to_name}}) func(s Scalar) (Scalar, error) {
return func(s Scalar) (Scalar, error) {
if t, ok := m[s.Actual{{$from_name}}()]; ok {
s.Sym = t
@ -120,48 +135,62 @@ import (
{{- $t := index $.types $r.type }}
{{- range $v := $r.variants }}
// Reader {{$r.name}}{{$v.name}}
{{- $range_start := 1 }}
{{- $range_stop := 1 }}
{{- if $v.range }}
{{- $range_start = index $v.range 0 }}
{{- $range_stop = index $v.range 1 }}
{{- end}}
func (d *D) Try{{$r.name}}{{$v.name}}({{$v.param}}) ({{$t.go_type}}, error) { return {{$v.call}} }
{{- range $n := xrange $range_start $range_stop }}
func (d *D) Scalar{{$r.name}}{{$v.name}}({{$v.param}}) func(Scalar) (Scalar, error) {
return func(s Scalar) (Scalar, error) {
v, err := {{$v.call}}
s.Actual = v
return s, err
}
}
// Reader {{$r.name}}{{replace $v.name "$n" $n}}
func (d *D) {{$r.name}}{{$v.name}}({{$v.param}}) {{$t.go_type}} {
v, err := {{$v.call}}
if err != nil {
panic(IOError{Err: err, Op: "{{$r.name}}{{$v.name}}", Pos: d.Pos()})
}
return v
}
// Try{{$r.name}}{{replace $v.name "$n" $n}} tries to read {{replace $v.doc "$n" $n}}
func (d *D) Try{{$r.name}}{{replace $v.name "$n" $n}}({{$v.params}}) ({{$t.go_type}}, error) { return {{replace $v.call "$n" $n}} }
func (d *D) TryField{{$r.name}}{{$v.name}}(name string{{if $v.param}}, {{$v.param}}{{end}}, sfns ...ScalarFn) ({{$t.go_type}}, error) {
{{- if $v.param}}
v, err := d.TryFieldScalar(name, d.Scalar{{$r.name}}{{$v.name}}({{$v.args}}), sfns...)
if err != nil {
return {{$t.zero}}, err
func (d *D) Scalar{{$r.name}}{{replace $v.name "$n" $n}}({{$v.params}}) func(Scalar) (Scalar, error) {
return func(s Scalar) (Scalar, error) {
v, err := {{replace $v.call "$n" $n}}
s.Actual = v
return s, err
}
return v.Actual{{$r.type}}(), err
{{- else}}
return d.TryField{{$r.type}}Fn(name, (*D).Try{{$r.name}}{{$v.name}}, sfns...)
{{- end}}
}
}
func (d *D) Field{{$r.name}}{{$v.name}}(name string{{if $v.param}}, {{$v.param}}{{end}}, sfns ...ScalarFn) {{$t.go_type}} {
{{- if $v.param}}
v, err := d.TryField{{$r.name}}{{$v.name}}(name{{if $v.args}}, {{$v.args}}{{end}}, sfns...)
// {{$r.name}}{{replace $v.name "$n" $n}} reads {{replace $v.doc "$n" $n}}
func (d *D) {{$r.name}}{{replace $v.name "$n" $n}}({{$v.params}}) {{$t.go_type}} {
v, err := {{replace $v.call "$n" $n}}
if err != nil {
panic(IOError{Err: err, Name: name, Op: "{{$r.name}}{{$v.name}}", Pos: d.Pos()})
panic(IOError{Err: err, Op: "{{$r.name}}{{replace $v.name "$n" $n}}", Pos: d.Pos()})
}
return v
{{- else}}
return d.Field{{$r.type}}Fn(name, (*D).{{$r.name}}{{$v.name}}, sfns...)
{{- end}}
}
}
// TryField{{$r.name}}{{replace $v.name "$n" $n}} tries to add a field and read {{replace $v.doc "$n" $n}}
func (d *D) TryField{{$r.name}}{{replace $v.name "$n" $n}}(name string{{if $v.params}}, {{$v.params}}{{end}}, sfns ...ScalarFn) ({{$t.go_type}}, error) {
{{- if $v.params}}
v, err := d.TryFieldScalar(name, d.Scalar{{$r.name}}{{replace $v.name "$n" $n}}({{$v.args}}), sfns...)
if err != nil {
return {{$t.zero}}, err
}
return v.Actual{{$r.type}}(), err
{{- else}}
return d.TryField{{$r.type}}Fn(name, (*D).Try{{$r.name}}{{replace $v.name "$n" $n}}, sfns...)
{{- end}}
}
// Field{{$r.name}}{{replace $v.name "$n" $n}} adds a field and reads {{replace $v.doc "$n" $n}}
func (d *D) Field{{$r.name}}{{replace $v.name "$n" $n}}(name string{{if $v.params}}, {{$v.params}}{{end}}, sfns ...ScalarFn) {{$t.go_type}} {
{{- if $v.params}}
v, err := d.TryField{{$r.name}}{{replace $v.name "$n" $n}}(name{{if $v.args}}, {{$v.args}}{{end}}, sfns...)
if err != nil {
panic(IOError{Err: err, Name: name, Op: "{{$r.name}}{{replace $v.name "$n" $n}}", Pos: d.Pos()})
}
return v
{{- else}}
return d.Field{{$r.type}}Fn(name, (*D).{{$r.name}}{{replace $v.name "$n" $n}}, sfns...)
{{- end}}
}
{{- end}}
{{- end}}
{{- end}}