Skip to content

Commit da848b5

Browse files
chore: Fury header add language field (#1612)
## What does this PR do? Add serialization language field for Fury Header in xlang_spec. ## Related issues #1607 ## Does this PR introduce any user-facing change? - [ ] Does this PR introduce any public API change? - [x] Does this PR introduce any binary protocol compatibility change? ## Benchmark <!-- When the PR has an impact on performance (if you don't know whether the PR will have an impact on performance, you can submit the PR first, and if it will have impact on performance, the code reviewer will explain it), be sure to attach a benchmark data here. --> --------- Signed-off-by: LiangliangSui <[email protected]>
1 parent 9687fd8 commit da848b5

File tree

8 files changed

+16
-9
lines changed

8 files changed

+16
-9
lines changed

docs/specification/xlang_serialization_spec.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,17 @@ Fury will write the byte order for that object into the data instead of converti
139139
Fury header consists starts one byte:
140140

141141
```
142-
| 2 bytes | 4 bits | 1 bit | 1 bit | 1 bit | 1 bit | optional 4 bytes |
143-
+--------------+---------------+-------+-------+--------+-------+------------------------------------+
144-
| magic number | reserved bits | oob | xlang | endian | null | unsigned int for meta start offset |
142+
| 2 bytes | 4 bits | 1 bit | 1 bit | 1 bit | 1 bit | 1 byte | optional 4 bytes |
143+
+--------------+---------------+-------+-------+--------+-------+------------+------------------------------------+
144+
| magic number | reserved bits | oob | xlang | endian | null | language | unsigned int for meta start offset |
145145
```
146146

147147
- magic number: used to identify fury serialization protocol, current version use `0x62d4`.
148148
- null flag: 1 when object is null, 0 otherwise. If an object is null, other bits won't be set.
149149
- endian flag: 1 when data is encoded by little endian, 0 for big endian.
150150
- xlang flag: 1 when serialization uses xlang format, 0 when serialization uses Fury java format.
151151
- oob flag: 1 when passed `BufferCallback` is not null, 0 otherwise.
152+
- language: the language when serializing objects, such as JAVA, PYTHON, GO, etc. Fury can use this flag to determine whether spend more time on serialization to make the deserialization faster for dynamic languages.
152153

153154
If meta share mode is enabled, an uncompressed unsigned int is appended to indicate the start offset of metadata.
154155

go/fury/fury.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ const (
8080
XLANG Language = iota
8181
JAVA
8282
PYTHON
83+
CPP
8384
GO
85+
JAVASCRIPT
86+
RUST
8487
)
8588

8689
const (

java/fury-core/src/main/java/org/apache/fury/config/Language.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ public enum Language {
2626
PYTHON,
2727
CPP,
2828
GO,
29+
JAVASCRIPT,
30+
RUST,
2931
}

javascript/packages/fury/lib/fury.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export default class {
111111
bitmap |= ConfigFlags.isCrossLanguageFlag;
112112
this.binaryWriter.int16(MAGIC_NUMBER);
113113
this.binaryWriter.uint8(bitmap);
114-
this.binaryWriter.uint8(Language.XLANG);
114+
this.binaryWriter.uint8(Language.JAVASCRIPT);
115115
const cursor = this.binaryWriter.getCursor();
116116
this.binaryWriter.skip(4); // preserve 4-byte for nativeObjects start offsets.
117117
this.binaryWriter.uint32(0); // nativeObjects length.

javascript/packages/fury/lib/type.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ export enum Language {
115115
PYTHON = 2,
116116
CPP = 3,
117117
GO = 4,
118+
JAVASCRIPT = 5,
119+
RUST = 6,
118120
}
119121

120122
export const MAGIC_NUMBER = 0x62D4;

python/pyfury/_fury.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,8 @@ class Language(enum.Enum):
586586
PYTHON = 2
587587
CPP = 3
588588
GO = 4
589+
JAVA_SCRIPT = 5
590+
RUST = 6
589591

590592

591593
@dataclass

rust/fury/src/deserializer.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,7 @@ impl<'de, 'bf: 'de> DeserializerState<'de, 'bf> {
241241

242242
fn head(&mut self) -> Result<(), Error> {
243243
let _bitmap = self.reader.u8();
244-
let language: Language = self.reader.u8().try_into()?;
245-
if Language::XLANG != language {
246-
return Err(Error::UnsupportLanguage { language });
247-
}
244+
let _language: Language = self.reader.u8().try_into()?;
248245
self.reader.skip(8); // native offset and size
249246
Ok(())
250247
}

rust/fury/src/serializer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl<'de> SerializerState<'de> {
347347
bitmap |= config_flags::IS_LITTLE_ENDIAN_FLAG;
348348
bitmap |= config_flags::IS_CROSS_LANGUAGE_FLAG;
349349
self.writer.u8(bitmap);
350-
self.writer.u8(Language::XLANG as u8);
350+
self.writer.u8(Language::RUST as u8);
351351
self.writer.skip(4); // native offset
352352
self.writer.skip(4); // native size
353353
self

0 commit comments

Comments
 (0)