The optional "binaryFormat" property designates the format of binary values embedded in JSON strings. The default value for "binaryFormat" is the "defaultBinaryFormat" defined in the "createSession" or "alterSession" actions. If it is omitted there, it defaults to the value of the "defaultBinaryFormat" property in the <faircom>/config/services.json file. If it is not there, the FairCom server defaults it to "hex". Prior to version 13.0.4, the server defaulted it to "base64".
Note Typically, response options apply only to the server’s response, but the
"binaryFormat"property applies to both the request and the response.
- The
"binaryFormat"property may occur inside"params","responseOptions","defaultResponseOptions","result", and"mapOfPropertiesToFields".- It occurs in
"params"when actions create or change values. - It occurs in
"responseOptions"when actions return values.
- It occurs in
- When
"binaryFormat"occurs in"params"it specifies how the sender represents binary values.- For example, when
"binaryFormat"is set to"hex", the FairCom server expects the binary values of fields and keys to be represented in strings with hexadecimal format.
- For example, when
- When
"binaryFormat"occurs in"responseOptions"or"defaultResponseOptions"it specifies how the FairCom server should represent binary values in responses.- For example, when
"binaryFormat"is set to"hex", the FairCom server represents binary values in strings with hexadecimal format.
- For example, when
- When
"binaryFormat"occurs in"result", it signifies how binary values are represented.- For example, when
"binaryFormat"is set to"base64", the FairCom server represents binary values in the response in base64 format.
- For example, when
- When
"binaryFormat"occurs in"mapOfPropertiesToFields", it tells the server how to encode or decode the binary value in a JSON property.- For example, including
"binaryFormat"in a"tableFieldsToJson"transform step controls how the server takes a raw binary field value and encodes it as a JSON property. - For example, including
"binaryFormat"in a"jsonToTableFields"or"jsonToDifferentTableFields"transform step controls how the server decodes a binary value in a JSON property so it can store the raw binary value in a field.
- For example, including
- The following are the possible values for each format.
-
"base64"- When the server reads and writes from a binary field, it represents the binary value as a base64 string.
- Base64 is harder for people to read and convert to binary.
- Base64 creates the smallest payload for the most efficient data transmission in JSON.
-
"base64"strings contain the characters0 - 9,A - Z,a - z,+,/, and=.
-
"hex"- When the server reads and writes from a binary field, it represents the binary value as a hexadecimal string.
- Hexadecimal is easier for people to read and convert to binary.
- Hexadecimal creates a 30% larger payload than
"base64", which makes it less efficient for data transmission. - Hexadecimal strings contain the characters
0 - 9andA - F.
-
"byteArray"- When the server reads and writes from a binary field, it represents the binary value as an array of bytes.
- An array of bytes is easiest for a program to manipulate.
- An array of bytes creates a larger payload than
"base64"and"hex", which makes it less efficient for data transmission. - An array of bytes returns a JSON array containing one integer number between
0and255for each byte in the binary value:"aBinaryField": [ 255, 0, 255 ]
-
Example requests
This example creates a table containing one binary field named "bin" with a fixed length of 5 bytes.
{
"api": "db",
"action": "createTable",
"params": {
"tableName": "binary_test",
"fields": [
{
"name": "bin",
"type": "binary",
"length": 5
}
]
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}
This example inserts a record with the ASCII characters "123" in the "bin" field. The value of "bin" is represented as an array of bytes.
{
"api": "db",
"action": "insertRecords",
"params": {
"tableName": "binary_test",
"dataFormat": "objects",
"binaryFormat": "byteArray",
"sourceData": [
{
"bin": [49,50,51]
}
]
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}
This example inserts a record with the ASCII characters "123" in the "bin" field. The value of "bin" is represented as a string in hexadecimal format.
{
"api": "db",
"action": "insertRecords",
"params": {
"tableName": "binary_test",
"dataFormat": "objects",
"binaryFormat": "hex",
"sourceData": [
{
"bin": "313233"
}
]
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}
This example inserts a record with the ASCII characters "123" in the "bin" field. The value of "bin" is represented as a string in base64 format.
{
"api": "db",
"action": "insertRecords",
"params": {
"tableName": "binary_test",
"dataFormat": "objects",
"binaryFormat": "base64",
"sourceData": [
{
"bin": "MTIz"
}
]
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}
This example requests the first record in the "binary_test" table with the value of "bin" represented as an array of bytes.
{
"api": "db",
"action": "getRecordsByTable",
"params": {
"tableName": "binary_test",
"maxRecords": 1
},
"responseOptions": {
"binaryFormat": "byteArray",
"dataFormat": "objects",
"numberFormat": "number"
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}
Response examples
Note Our examples insert only 3 bytes into
"bin". Because the"bin"field has a fixed length of 5 bytes, the server pads unused bytes with0x00and stores the result. When a record is retrieved, the server returns all 5 bytes.
{
"result": {
"dataFormat": "objects",
"binaryFormat": "byteArray",
"fields": [
{ "name": "id", "type": "bigint", "length": null, "scale": null, "autoTimestamp": "none", "defaultValue": null, "nullable": false, "primaryKey": 1 },
{ "name": "changeId", "type": "bigint", "length": null, "scale": null, "autoTimestamp": "none", "defaultValue": null, "nullable": true, "primaryKey": 0 },
{ "name": "bin", "type": "binary", "length": 5, "scale": null, "autoTimestamp": "none", "defaultValue": null, "nullable": true, "primaryKey": 0 }
],
"data": [
{
"bin": [49,50,51,0,0],
"changeId": 50217,
"id": 1
}
],
"moreRecords": true,
"requestedRecordCount": 1,
"returnedRecordCount": 1,
"totalRecordCount": 3
},
"errorCode": 0,
"errorMessage": "",
"authToken": "replaceWithAuthTokenFromCreateSession"
}
This example requests the first record in the "binary_test" table with the value of "bin" represented as a hexadecimal string.
{
"api": "db",
"action": "getRecordsByTable",
"params": {
"tableName": "binary_test",
"maxRecords": 1
},
"responseOptions": {
"binaryFormat": "hex",
"dataFormat": "objects",
"numberFormat": "number"
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}
{
"result": {
"dataFormat": "objects",
"binaryFormat": "byteArray",
"fields": [
{ "name": "id", "type": "bigint", "length": null, "scale": null, "autoTimestamp": "none", "defaultValue": null, "nullable": false, "primaryKey": 1 },
{ "name": "changeId", "type": "bigint", "length": null, "scale": null, "autoTimestamp": "none", "defaultValue": null, "nullable": true, "primaryKey": 0 },
{ "name": "bin", "type": "binary", "length": 5, "scale": null, "autoTimestamp": "none", "defaultValue": null, "nullable": true, "primaryKey": 0 }
],
"data": [
{
"bin": "3132330000",
"changeId": 50217,
"id": 1
}
],
"moreRecords": true,
"requestedRecordCount": 1,
"returnedRecordCount": 1,
"totalRecordCount": 3
},
"errorCode": 0,
"errorMessage": "",
"authToken": "replaceWithAuthTokenFromCreateSession"
}
This example requests the first record in the "binary_test" table with the value of "bin" represented as a base64 string.
{
"api": "db",
"action": "getRecordsByTable",
"params": {
"tableName": "binary_test",
"maxRecords": 1
},
"responseOptions": {
"binaryFormat": "base64",
"dataFormat": "objects",
"numberFormat": "number"
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}
Response
{
"result": {
"dataFormat": "objects",
"binaryFormat": "byteArray",
"fields": [
{ "name": "id", "type": "bigint", "length": null, "scale": null, "autoTimestamp": "none", "defaultValue": null, "nullable": false, "primaryKey": 1 },
{ "name": "changeId", "type": "bigint", "length": null, "scale": null, "autoTimestamp": "none", "defaultValue": null, "nullable": true, "primaryKey": 0 },
{ "name": "bin", "type": "binary", "length": 5, "scale": null, "autoTimestamp": "none", "defaultValue": null, "nullable": true, "primaryKey": 0 }
],
"data": [
{
"bin": "MTIzAAA=",
"changeId": 50217,
"id": 1
}
],
"moreRecords": true,
"requestedRecordCount": 1,
"returnedRecordCount": 1,
"totalRecordCount": 3
},
"errorCode": 0,
"errorMessage": "",
"authToken": "replaceWithAuthTokenFromCreateSession"
}