public class Token extends Object
Processing and optimization could be run over a list of Tokens to perform various functions
IR could be used to generate code or other specifications. It should be possible to do the following:
IR could be serialized to storage or network via code generated by SBE. Then read back in to
a List of Token
s.
The entire IR of an entity is a List
of Token
objects. The order of this list is very
important. Encoding of fields is done by nodes pointing to specific encoding
PrimitiveType
objects. Each encoding node contains encodedLength, offset, byte order,
and Encoding
. Entities relevant to the encoding such as fields, messages, repeating groups, etc. are
encapsulated in the list as nodes themselves. Although, they will in most cases never be serialized. The boundaries
of these entities are delimited by BEGIN and END Signal
values in the node Encoding
.
A list structure like this allows for each concatenation of encodings as well as easy traversal.
An example encoding of a message headerStructure might be like this.
Modifier and Type | Class and Description |
---|---|
static class |
Token.Builder
Builder for
Token which can simplify construction. |
Modifier and Type | Field and Description |
---|---|
static int |
INVALID_ID
Invalid ID value.
|
static int |
VARIABLE_LENGTH
Length not determined
|
Constructor and Description |
---|
Token(Signal signal,
String name,
String referencedName,
String description,
String packageName,
int id,
int version,
int deprecated,
int encodedLength,
int offset,
int componentTokenCount,
Encoding encoding)
Construct an
Token by providing values for all fields. |
Modifier and Type | Method and Description |
---|---|
String |
applicableTypeName()
Get the name of the type that should be applied in context.
|
int |
arrayLength()
The number of encoded primitives in this type.
|
int |
componentTokenCount()
The number of tokens that make up this component.
|
void |
componentTokenCount(int componentTokenCount)
Set the number of tokens this component has.
|
int |
deprecated()
The version in which this context was deprecated.
|
String |
description()
Description for what the token is to be used for.
|
int |
encodedLength()
The encodedLength of this token in bytes.
|
void |
encodedLength(int encodedLength)
Set the encoded length for this node.
|
Encoding |
encoding()
|
int |
id()
Return the ID of the token assigned by the specification
|
boolean |
isConstantEncoding()
Is the encoding presence is a constant or not?
|
boolean |
isOptionalEncoding()
Is the encoding presence is optional or not?
|
CharSequence |
matchOnLength(Supplier<CharSequence> one,
Supplier<CharSequence> many)
Match which approach to take based on the length of the token.
|
String |
name()
Return the name of the token
|
int |
offset()
The offset for this token in the message.
|
String |
packageName()
Return the packageName of the token
|
String |
referencedName()
Get the name of the type when this is from a reference.
|
Signal |
signal()
Signal the role of this token.
|
String |
toString() |
int |
version()
The version context for this token.
|
public static final int INVALID_ID
public static final int VARIABLE_LENGTH
public Token(Signal signal, String name, String referencedName, String description, String packageName, int id, int version, int deprecated, int encodedLength, int offset, int componentTokenCount, Encoding encoding)
Token
by providing values for all fields.signal
- for the token role.name
- of the token in the message.referencedName
- of the type when created from a ref in a composite.description
- of what the token is for.packageName
- of the token in the message. Use null, except for BEGIN_MESSAGE tokens for types that
require an explicit package.id
- as the identifier in the message declaration.version
- application within the template.deprecated
- as of this version.encodedLength
- of the component part.offset
- in the underlying message as octets.componentTokenCount
- number of tokens in this component.encoding
- of the primitive field.public String name()
public String packageName()
public String referencedName()
public String description()
public int id()
public int version()
public int deprecated()
public String applicableTypeName()
public int encodedLength()
VARIABLE_LENGTH
means this node represents a variable length field.public void encodedLength(int encodedLength)
encodedLength()
.encodedLength
- that is overriding existing value.public int arrayLength()
public CharSequence matchOnLength(Supplier<CharSequence> one, Supplier<CharSequence> many)
String
is returned.one
- to be used when length is one.many
- to be used when length is greater than one.CharSequence
representing the token depending on the length.public int offset()
VARIABLE_LENGTH
means this node's true offset is dependent on variable length
fields ahead of it in the encoding.public int componentTokenCount()
public void componentTokenCount(int componentTokenCount)
componentTokenCount
- the number of tokens this component has.public boolean isConstantEncoding()
public boolean isOptionalEncoding()
Copyright © 2013-2024 Real Logic Limited. All Rights Reserved.